Skip to content

Commit

Permalink
Setting exit status to 1 if can't parse input.
Browse files Browse the repository at this point in the history
  • Loading branch information
Valloric committed Jul 19, 2014
1 parent 1703bcc commit 3e1408e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
17 changes: 12 additions & 5 deletions nailgun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use std::os;
use std::io::File;
use std::io::TempDir;
use std::io::Command;
use std::io::process::ExitStatus;
use std::path::Path;
use self::prelude::PRELUDE;
use self::printer::PRINTER_MAIN;
Expand Down Expand Up @@ -109,13 +110,19 @@ fn printParseTree( grammar_code: &str, input_path: &str ) {
};

let printer = temp_dir.path().join( "printer" );
let output = match Command::new(
printer.as_str().unwrap() ).arg( input_path ).output() {
Ok( output ) => output.output,
let command_output = Command::new(
printer.as_str().unwrap() ).arg( input_path ).output();

match command_output {
Ok( output ) => {
println!( "{}", String::from_utf8_lossy( output.output.as_slice() ) );
os::set_exit_status( match output.status {
ExitStatus( code ) => code,
_ => 1
} );
},
Err( e ) => fail!( "Failed to execute process: {}", e ),
};

println!( "{}", String::from_utf8_lossy( output.as_slice() ) );
}


Expand Down
5 changes: 4 additions & 1 deletion printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ fn main() {
let args = std::os::args();
match parse( inputFromFile( args.get( 1 ).as_slice() ).as_slice() ) {
Some( ref node ) => println!( "{}", node ),
_ => println!( "Couldn't parse input." )
_ => {
println!( "Couldn't parse input." );
std::os::set_exit_status( 1 );
}
};
}
"###;

0 comments on commit 3e1408e

Please sign in to comment.