diff options
author | Matthias Beyer <matthias.beyer@atos.net> | 2019-04-30 14:22:14 +0200 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@atos.net> | 2019-04-30 14:29:06 +0200 |
commit | 792e9e695353c94e16f199c2d846e53a178e2e4e (patch) | |
tree | edc062e3a59340a7675acef121772476d453033f | |
parent | 8278531c9851bc31e6f81a30a907297c79d532d9 (diff) |
Simplify error handling
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/main.rs | 32 |
2 files changed, 18 insertions, 15 deletions
@@ -19,6 +19,7 @@ log = "0.4" flexi_logger = "0.11" prettytable-rs = "0.8" filters = "0.3" +boolinator = "2" [dependencies.clap] version = ">=2.33" diff --git a/src/main.rs b/src/main.rs index 13b42a0..04c165c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ extern crate url; extern crate xdg; extern crate flexi_logger; extern crate filters; +extern crate boolinator; #[cfg(feature = "compare_csv")] extern crate csv; @@ -32,6 +33,7 @@ use failure::ResultExt; use failure::Fallible as Result; use clap::ArgMatches; use filters::filter::Filter; +use boolinator::Boolinator; use config::Configuration; use compare::ComparePackage; @@ -193,21 +195,21 @@ fn app() -> Result<()> { }, (other, _mtch) => { - if app.is_present("input_stdin") { - // Ugly, but works: - // If we have "--stdin" on CLI, we have a CLI/Stdin backend, which means that we can query - // _any_ "project", and get the stdin anyways. This is really not like it should be, but - // works for now - let packages = backend - .project("")? - .into_iter() - .filter(|package| repository_filter.filter(package.repo())) - .collect(); - frontend.list_packages(packages)?; - } else { - error!("Unknown command: '{}'", other); - ::std::process::exit(1) - } + app.is_present("input_stdin") + .as_result((), Error::from(format_err!("Input not from stdin"))) + .and_then(|_| { + // Ugly, but works: + // If we have "--stdin" on CLI, we have a CLI/Stdin backend, which means that we can query + // _any_ "project", and get the stdin anyways. This is really not like it should be, but + // works for now + let packages = backend + .project("")? + .into_iter() + .filter(|package| repository_filter.filter(package.repo())) + .collect(); + frontend.list_packages(packages) + }) + .map_err(|_| format_err!("Unknown command: {}", other)) } } |