Require version and help text to be on stdout

This commit is contained in:
Benjamin Sago 2017-06-23 22:03:58 +01:00
parent 90e0c5b60e
commit a060782312
2 changed files with 10 additions and 6 deletions

View File

@ -1,5 +1,5 @@
extern crate exa;
use exa::Exa;
use exa::{Exa, Misfire};
use std::env::args_os;
use std::io::{stdout, stderr, Write, ErrorKind};
@ -7,9 +7,7 @@ use std::process::exit;
fn main() {
let args = args_os().skip(1);
let mut stdout = stdout();
match Exa::new(args, &mut stdout) {
match Exa::new(args, &mut stdout()) {
Ok(mut exa) => {
match exa.run() {
Ok(exit_status) => exit(exit_status),
@ -24,6 +22,12 @@ fn main() {
}
};
},
Err(e@Misfire::Help(_)) | Err(e@Misfire::Version) => {
writeln!(stdout(), "{}", e).unwrap();
exit(e.error_code());
},
Err(e) => {
writeln!(stderr(), "{}", e).unwrap();
exit(e.error_code());

View File

@ -110,7 +110,7 @@ $exa $testcases/git/additions -l --git 2>&1 | diff -q - $results/git_additions
$exa $testcases/git/edits -l --git 2>&1 | diff -q - $results/git_edits || exit 1
# And finally...
$exa --help 2>&1 | diff -q - $results/help || exit 1
$exa --help --long 2>&1 | diff -q - $results/help_long || exit 1
$exa --help | diff -q - $results/help || exit 1
$exa --help --long | diff -q - $results/help_long || exit 1
echo "All the tests passed!"