File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -51,16 +51,23 @@ fn rev() -> String {
5151}
5252
5353fn commit_hash ( ) -> Option < String > {
54- output_to_string ( "git rev-parse --short HEAD" )
54+ exec ( "git rev-parse --short HEAD" ) . ok ( )
5555}
5656
5757fn build_date ( ) -> Option < String > {
58- output_to_string ( "date -u +%Y-%m-%d" )
58+ exec ( "date -u +%Y-%m-%d" ) . ok ( )
5959}
6060
61- fn output_to_string ( command : & str ) -> Option < String > {
61+ fn exec ( command : & str ) -> std :: io :: Result < String > {
6262 let args = command. split_ascii_whitespace ( ) . collect :: < Vec < _ > > ( ) ;
63- let output = Command :: new ( args[ 0 ] ) . args ( & args[ 1 ..] ) . output ( ) . ok ( ) ?;
64- let stdout = String :: from_utf8 ( output. stdout ) . ok ( ) ?;
65- Some ( stdout. trim ( ) . to_string ( ) )
63+ let output = Command :: new ( args[ 0 ] ) . args ( & args[ 1 ..] ) . output ( ) ?;
64+ if !output. status . success ( ) {
65+ return Err ( std:: io:: Error :: new (
66+ std:: io:: ErrorKind :: InvalidData ,
67+ format ! ( "command {:?} returned non-zero code" , command, ) ,
68+ ) ) ;
69+ }
70+ let stdout = String :: from_utf8 ( output. stdout )
71+ . map_err ( |err| std:: io:: Error :: new ( std:: io:: ErrorKind :: InvalidData , err) ) ?;
72+ Ok ( stdout. trim ( ) . to_string ( ) )
6673}
You can’t perform that action at this time.
0 commit comments