File tree Expand file tree Collapse file tree 2 files changed +23
-13
lines changed
Expand file tree Collapse file tree 2 files changed +23
-13
lines changed Original file line number Diff line number Diff line change 1- use anyhow:: Result ;
1+ use anyhow:: { anyhow , Context , Result } ;
22use std:: process:: { Command , Stdio } ;
33
44use crate :: logs:: log;
@@ -74,13 +74,29 @@ pub fn generate_known_actions() -> Vec<MenuAction> {
7474pub fn execute_shell_operation ( path : & String , command_template : & str ) -> Result < ( ) > {
7575 let cmd = String :: from ( command_template) . replace ( "{}" , path) ;
7676 log ( format ! ( "Executing command: {:?}" , cmd) . as_str ( ) ) ;
77- let mut c = Command :: new ( "sh" )
77+ let c = Command :: new ( "sh" )
7878 . arg ( "-c" )
7979 . arg ( cmd. clone ( ) )
8080 . stdin ( Stdio :: inherit ( ) )
8181 . stderr ( Stdio :: piped ( ) )
8282 . stdout ( Stdio :: piped ( ) )
83- . spawn ( ) ?;
84- c. wait ( ) ?;
83+ . spawn ( )
84+ . context ( "failed to start a command" ) ?;
85+ let output = c
86+ . wait_with_output ( )
87+ . context ( "failed to read command output" ) ?;
88+
89+ if !output. status . success ( ) {
90+ let error = format ! (
91+ "Failed to execute command: {:?}, {}\n {}\n {}" ,
92+ cmd,
93+ output. status,
94+ String :: from_utf8_lossy( & output. stderr) ,
95+ String :: from_utf8_lossy( & output. stdout) ,
96+ ) ;
97+ log ( error. as_str ( ) ) ;
98+ return Err ( anyhow ! ( error) ) ;
99+ }
100+
85101 Ok ( ( ) )
86102}
Original file line number Diff line number Diff line change @@ -34,18 +34,12 @@ pub fn on_key_tree(app: &mut App, key_event: KeyEvent) {
3434 KeyCode :: Char ( 'u' ) if key_event. modifiers == KeyModifiers :: CONTROL => {
3535 app. clear_search_text ( ) ;
3636 }
37- KeyCode :: Backspace => {
38- app. backspace_search_text ( ) ;
39- }
37+ KeyCode :: Backspace => app. backspace_search_text ( ) ,
4038 KeyCode :: Char ( 'w' ) if key_event. modifiers == KeyModifiers :: CONTROL => {
4139 app. backspace_search_text ( ) ;
4240 }
43- KeyCode :: Char ( c) => {
44- app. type_search_text ( c) ;
45- }
46- _ => {
47- log ( format ! ( "Key event: {:?}" , key_event) . as_str ( ) ) ;
48- }
41+ KeyCode :: Char ( c) => app. type_search_text ( c) ,
42+ _ => log ( format ! ( "Key event: {:?}" , key_event) . as_str ( ) ) ,
4943 } ;
5044}
5145
You can’t perform that action at this time.
0 commit comments