@@ -19,15 +19,38 @@ pub trait CommandExt {
19
19
) -> Result < ExitStatus , CommandError > ;
20
20
fn run_and_get_stdout ( & mut self , verbose : bool ) -> Result < String > ;
21
21
fn run_and_get_output ( & mut self , verbose : bool ) -> Result < std:: process:: Output > ;
22
+ fn command_pretty ( & self ) -> String ;
22
23
}
23
24
24
25
impl CommandExt for Command {
26
+ fn command_pretty ( & self ) -> String {
27
+ // a dummy implementor of display to avoid using unwraps
28
+ struct C < ' c > ( & ' c Command ) ;
29
+ impl std:: fmt:: Display for C < ' _ > {
30
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
31
+ let cmd = self . 0 ;
32
+ write ! ( f, "{}" , cmd. get_program( ) . to_string_lossy( ) ) ?;
33
+ let args = cmd. get_args ( ) ;
34
+ if args. len ( ) > 1 {
35
+ write ! ( f, " " ) ?;
36
+ write ! (
37
+ f,
38
+ "{}" ,
39
+ shell_words:: join( args. map( |o| o. to_string_lossy( ) ) )
40
+ ) ?;
41
+ }
42
+ Ok ( ( ) )
43
+ }
44
+ }
45
+ format ! ( "{}" , C ( self ) )
46
+ }
47
+
25
48
fn print_verbose ( & self , verbose : bool ) {
26
49
if verbose {
27
50
if let Some ( cwd) = self . get_current_dir ( ) {
28
- println ! ( "+ {:?} {:? }" , cwd, self ) ;
51
+ println ! ( "+ {:?} {}" , cwd, self . command_pretty ( ) ) ;
29
52
} else {
30
- println ! ( "+ {:? }" , self ) ;
53
+ println ! ( "+ {}" , self . command_pretty ( ) ) ;
31
54
}
32
55
}
33
56
}
@@ -42,7 +65,7 @@ impl CommandExt for Command {
42
65
} else {
43
66
Err ( CommandError :: NonZeroExitCode {
44
67
status,
45
- command : format ! ( "{ self:?}" ) ,
68
+ command : self . command_pretty ( ) ,
46
69
stderr : output. map ( |out| out. stderr . clone ( ) ) . unwrap_or_default ( ) ,
47
70
stdout : output. map ( |out| out. stdout . clone ( ) ) . unwrap_or_default ( ) ,
48
71
} )
@@ -68,7 +91,7 @@ impl CommandExt for Command {
68
91
self . status ( )
69
92
. map_err ( |e| CommandError :: CouldNotExecute {
70
93
source : Box :: new ( e) ,
71
- command : format ! ( "{ self:?}" ) ,
94
+ command : self . command_pretty ( ) ,
72
95
} )
73
96
. map_err ( Into :: into)
74
97
}
@@ -91,7 +114,7 @@ impl CommandExt for Command {
91
114
self . output ( ) . map_err ( |e| {
92
115
CommandError :: CouldNotExecute {
93
116
source : Box :: new ( e) ,
94
- command : format ! ( "{ self:?}" ) ,
117
+ command : self . command_pretty ( ) ,
95
118
}
96
119
. to_section_report ( )
97
120
} )
0 commit comments