diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2019-04-19 17:54:52 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2019-04-19 17:58:33 +0200 |
commit | 7cc25e9cf2dda28f1f8dea43caac7bd6291ed1f1 (patch) | |
tree | 9fa1b948ac6ff7179fb311b54e60f1e41a97087c /src/frontend/mod.rs |
Initial import
In the beginning there was darkness.
So I spoke "git init".
And there was a git repository.
Diffstat (limited to 'src/frontend/mod.rs')
-rw-r--r-- | src/frontend/mod.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/frontend/mod.rs b/src/frontend/mod.rs new file mode 100644 index 0000000..41ab972 --- /dev/null +++ b/src/frontend/mod.rs @@ -0,0 +1,40 @@ +use clap::ArgMatches; +use failure::Fallible as Result; + +use librepology::v1::types::*; + +use crate::config::Configuration; +use crate::frontend::list::ListFrontend; +use crate::frontend::json::JsonFrontend; +use crate::frontend::table::TableFrontend; + +pub trait Frontend { + fn list_packages(&self, packages: Vec<Package>) -> Result<()>; + fn list_problems(&self, problems: Vec<Problem>) -> Result<()>; +} + +pub mod list; +pub mod json; +pub mod table; + +pub fn new_frontend(app: &ArgMatches, _config: &Configuration) -> Result<Box<Frontend>> { + match app.value_of("output") { + None | Some("lines") => { + debug!("No output specified, using default"); + Ok(Box::new(ListFrontend::new(::std::io::stdout()))) + }, + + Some("json") => { + debug!("Using JSON Frontend"); + Ok(Box::new(JsonFrontend::new(::std::io::stdout()))) + }, + + Some("table") => { + debug!("Using table Frontend"); + Ok(Box::new(TableFrontend::new(::std::io::stdout()))) + }, + + Some(other) => Err(format_err!("Unknown Frontend '{}'", other)), + } + +} |