Do table output by default

This commit is contained in:
Matthias Beyer 2018-03-23 15:58:45 +01:00
parent fd91662ed9
commit 9c13c276fb
3 changed files with 36 additions and 11 deletions

View file

@ -26,6 +26,7 @@ log = "0.4.0"
url = "1.5"
toml = "0.4"
toml-query = "0.6"
prettytable-rs = "0.6"
libimagstore = { version = "0.7.0", path = "../../../lib/core/libimagstore" }
libimagrt = { version = "0.7.0", path = "../../../lib/core/libimagrt" }

View file

@ -35,6 +35,7 @@
#[macro_use] extern crate log;
extern crate clap;
extern crate url;
#[macro_use] extern crate prettytable;
#[cfg(test)] extern crate toml;
#[cfg(test)] extern crate toml_query;
#[cfg(test)] extern crate env_logger;
@ -263,23 +264,28 @@ fn list_linkings(rt: &Runtime) {
.unwrap(); // safed by clap
let list_externals = cmd.is_present("list-externals-too");
let list_plain = cmd.is_present("list-plain");
let mut tab = ::prettytable::Table::new();
tab.set_titles(row!["#", "Link"]);
for entry in cmd.values_of("entries").unwrap() { // safed by clap
match rt.store().get(PathBuf::from(entry)) {
Ok(Some(entry)) => {
let mut i = 0;
for link in entry.get_internal_links().map_err_trace_exit_unwrap(1) {
for (i, link) in entry.get_internal_links().map_err_trace_exit_unwrap(1).enumerate() {
let link = link
.to_str()
.map_warn_err(|e| format!("Failed to convert StoreId to string: {:?}", e))
.ok();
if let Some(link) = link {
let _ = writeln!(rt.stdout(), "{: <3}: {}", i, link)
.to_exit_code()
.unwrap_or_exit();
i += 1;
if list_plain {
let _ = writeln!(rt.stdout(), "{: <3}: {}", i, link)
.to_exit_code()
.unwrap_or_exit();
} else {
tab.add_row(row![i, link]);
}
}
}
@ -292,10 +298,13 @@ fn list_linkings(rt: &Runtime) {
.map_err_trace_exit_unwrap(1)
.into_string();
let _ = writeln!(rt.stdout(), "{: <3}: {}", i, link)
.to_exit_code()
.unwrap_or_exit();
if list_plain {
let _ = writeln!(rt.stdout(), "{: <3}: {}", i, link)
.to_exit_code()
.unwrap_or_exit();
} else {
tab.add_row(row![i, link]);
}
})
}
},
@ -303,6 +312,14 @@ fn list_linkings(rt: &Runtime) {
Err(e) => trace_error(&e),
}
}
if !list_plain {
let out = rt.stdout();
let mut lock = out.lock();
tab.print(&mut lock)
.to_exit_code()
.unwrap_or_exit();
}
}
#[cfg(test)]

View file

@ -67,6 +67,13 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.takes_value(false)
.required(false)
.help("Also list external links (debugging helper that might be removed at some point"))
.arg(Arg::with_name("list-plain")
.long("plain")
.multiple(false)
.takes_value(false)
.required(false)
.help("List plain rather than in ASCII table"))
)
.arg(Arg::with_name("check-consistency")