Adds a debug option for espanso when executing shell commands for greater context
This commit is contained in:
		
							parent
							
								
									c12eae9d0a
								
							
						
					
					
						commit
						8030cf16ca
					
				|  | @ -123,7 +123,7 @@ impl super::Extension for ShellExtension { | ||||||
|     fn calculate(&self, params: &Mapping, args: &Vec<String>) -> Option<String> { |     fn calculate(&self, params: &Mapping, args: &Vec<String>) -> Option<String> { | ||||||
|         let cmd = params.get(&Value::from("cmd")); |         let cmd = params.get(&Value::from("cmd")); | ||||||
|         if cmd.is_none() { |         if cmd.is_none() { | ||||||
|             warn!("No 'cmd' parameter specified for shell variable"); |             warn!("No 'cmd' parameter specified for shell `iable"); | ||||||
|             return None; |             return None; | ||||||
|         } |         } | ||||||
|         let cmd = cmd.unwrap().as_str().unwrap(); |         let cmd = cmd.unwrap().as_str().unwrap(); | ||||||
|  | @ -171,6 +171,19 @@ impl super::Extension for ShellExtension { | ||||||
|                     warn!("Shell command reported error: \n{}", error_str); |                     warn!("Shell command reported error: \n{}", error_str); | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|  |                 // Check if debug flag set, provide additional context when an error occurs.
 | ||||||
|  |                 let debug_opt = params.get(&Value::from("debug")); | ||||||
|  |                 let with_debug = if let Some(value) = debug_opt { | ||||||
|  |                     let val = value.as_bool(); | ||||||
|  |                     val.unwrap_or(false) | ||||||
|  |                 }else{ | ||||||
|  |                     false | ||||||
|  |                 }; | ||||||
|  |                 
 | ||||||
|  |                 if with_debug { | ||||||
|  |                     error!("debug for shell cmd '{}', exit_status '{}', stdout '{}', stderr '{}'", cmd, output.status, output_str, error_str); | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|                 // If specified, trim the output
 |                 // If specified, trim the output
 | ||||||
|                 let trim_opt = params.get(&Value::from("trim")); |                 let trim_opt = params.get(&Value::from("trim")); | ||||||
|                 let should_trim = if let Some(value) = trim_opt { |                 let should_trim = if let Some(value) = trim_opt { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user