summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-03-23 19:37:13 +0100
committerGitHub <noreply@github.com>2018-03-23 19:37:13 +0100
commit7907ed96c72d8fe52b9e6bf281ddaeccf0f6d70e (patch)
tree8c416d994440b0075ace15c6165d2c1ed8ac5aa7
parent3416cf247be77451821ce4adcf964319b816491e (diff)
parent9c13c276fb0f556f159ea90d632c4c9cd830cab1 (diff)
downloadimag-7907ed96c72d8fe52b9e6bf281ddaeccf0f6d70e.zip
imag-7907ed96c72d8fe52b9e6bf281ddaeccf0f6d70e.tar.gz
Merge pull request #1368 from matthiasbeyer/imag-link/list-output-table
imag-link: Do table output by default
-rw-r--r--bin/core/imag-link/Cargo.toml1
-rw-r--r--bin/core/imag-link/src/main.rs39
-rw-r--r--bin/core/imag-link/src/ui.rs7
3 files changed, 36 insertions, 11 deletions
diff --git a/bin/core/imag-link/Cargo.toml b/bin/core/imag-link/Cargo.toml
index 607f5a0..3c2d3a3 100644
--- a/bin/core/imag-link/Cargo.toml
+++ b/bin/core/imag-link/Cargo.toml
@@ -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" }
diff --git a/bin/core/imag-link/src/main.rs b/bin/core/imag-link/src/main.rs
index 7f67b53..d68142b 100644
--- a/bin/core/imag-link/src/main.rs
+++ b/bin/core/imag-link/src/main.rs
@@ -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)]
diff --git a/bin/core/imag-link/src/ui.rs b/bin/core/imag-link/src/ui.rs
index f43812c..3f3136e 100644
--- a/bin/core/imag-link/src/ui.rs
+++ b/bin/core/imag-link/src/ui.rs
@@ -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")