Selaa lähdekoodia

Require version and help text to be on stdout

Benjamin Sago 8 vuotta sitten
vanhempi
sitoutus
a060782312
2 muutettua tiedostoa jossa 10 lisäystä ja 6 poistoa
  1. 8 4
      src/bin/main.rs
  2. 2 2
      xtests/run.sh

+ 8 - 4
src/bin/main.rs

@@ -1,5 +1,5 @@
 extern crate exa;
 extern crate exa;
-use exa::Exa;
+use exa::{Exa, Misfire};
 
 
 use std::env::args_os;
 use std::env::args_os;
 use std::io::{stdout, stderr, Write, ErrorKind};
 use std::io::{stdout, stderr, Write, ErrorKind};
@@ -7,9 +7,7 @@ use std::process::exit;
 
 
 fn main() {
 fn main() {
     let args = args_os().skip(1);
     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) => {
         Ok(mut exa) => {
             match exa.run() {
             match exa.run() {
                 Ok(exit_status) => exit(exit_status),
                 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) => {
         Err(e) => {
             writeln!(stderr(), "{}", e).unwrap();
             writeln!(stderr(), "{}", e).unwrap();
             exit(e.error_code());
             exit(e.error_code());

+ 2 - 2
xtests/run.sh

@@ -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
 $exa $testcases/git/edits     -l --git 2>&1 | diff -q - $results/git_edits      || exit 1
 
 
 # And finally...
 # 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!"
 echo "All the tests passed!"