blob: 0027fd844afd1f1b691fd0a0a157b25546ccf54e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
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;
use crate::backend::Backend;
pub trait Frontend {
fn list_packages(&self, packages: Vec<Package>) -> Result<()>;
fn list_problems(&self, problems: Vec<Problem>) -> Result<()>;
fn compare_packages(&self, packages: Vec<Package>, backend: &Backend, filter_repos: Vec<Repo>) -> 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)),
}
}
|