From 3e1408efb895800a09080bb580712ed32e6f1e58 Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Sat, 19 Jul 2014 10:22:43 -0700 Subject: [PATCH] Setting exit status to 1 if can't parse input. --- nailgun.rs | 17 ++++++++++++----- printer.rs | 5 ++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/nailgun.rs b/nailgun.rs index 9001758..e7979a6 100644 --- a/nailgun.rs +++ b/nailgun.rs @@ -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; @@ -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() ) ); } diff --git a/printer.rs b/printer.rs index a4f7829..bbc0008 100644 --- a/printer.rs +++ b/printer.rs @@ -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 ); + } }; } "###;