summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-12-24 12:38:46 +0100
committerMatthias Beyer <mail@beyermatthias.de>2019-12-25 13:45:58 +0100
commit60298dd04a2c8fe48bc58ef1d5430538b1996b46 (patch)
tree65c6a454977d90a3b9dd6448939e4ff5725a574b
parent63e2399266157204216f479e3476adfca6838715 (diff)
downloadimag-60298dd04a2c8fe48bc58ef1d5430538b1996b46.tar.gz
imag-60298dd04a2c8fe48bc58ef1d5430538b1996b46.tar.xz
-rw-r--r--bin/core/imag-tag/src/lib.rs29
1 files changed, 21 insertions, 8 deletions
diff --git a/bin/core/imag-tag/src/lib.rs b/bin/core/imag-tag/src/lib.rs
index 3e931609..0211d3f1 100644
--- a/bin/core/imag-tag/src/lib.rs
+++ b/bin/core/imag-tag/src/lib.rs
@@ -89,7 +89,7 @@ impl ImagApplication for ImagTag {
let process = |iter: &mut dyn Iterator<Item = Result<StoreId>>| -> Result<()> {
match rt.cli().subcommand() {
("list", _) => iter
- .map_ok(|id| list(id, &rt))
+ .map_ok(|id| list(id, &rt, true))
.collect::<Result<Vec<_>>>()
.map(|_| ()),
@@ -185,6 +185,13 @@ impl ImagApplication for ImagTag {
.map(|_| ())
},
+ (_, None) => {
+ debug!("No subcommand, using 'list'");
+ iter.map_ok(|id| list(id, &rt, false))
+ .collect::<Result<Vec<_>>>()
+ .map(|_| ())
+ },
+
(other, _) => {
debug!("Unknown command");
if rt.handle_unknown_subcommand("imag-tag", other, rt.cli())?.success() {
@@ -253,13 +260,19 @@ fn alter(rt: &Runtime, path: StoreId, add: Option<Vec<Tag>>, rem: Option<Vec<Tag
rt.report_touched(&path)
}
-fn list(path: StoreId, rt: &Runtime) -> Result<()> {
+fn list(path: StoreId, rt: &Runtime, has_subcommand: bool) -> Result<()> {
let entry = rt.store().get(path.clone())?.ok_or_else(|| err_msg("No entry found"))?;
- let scmd = rt.cli().subcommand_matches("list").unwrap(); // safe, we checked in main()
- let json_out = scmd.is_present("json");
- let line_out = scmd.is_present("linewise");
- let sepp_out = scmd.is_present("sep");
- let mut comm_out = scmd.is_present("commasep");
+ let (scmd, json_out, line_out, sepp_out, mut comm_out) = if has_subcommand {
+ let scmd = rt.cli().subcommand_matches("list").unwrap();
+ let json_out = scmd.is_present("json");
+ let line_out = scmd.is_present("linewise");
+ let sepp_out = scmd.is_present("sep");
+ let comm_out = scmd.is_present("commasep");
+
+ (Some(scmd), json_out, line_out, sepp_out, comm_out)
+ } else {
+ (None, false, false, false, false)
+ };
if !vec![json_out, line_out, comm_out, sepp_out].iter().any(|v| *v) {
// None of the flags passed, go to default
@@ -279,7 +292,7 @@ fn list(path: StoreId, rt: &Runtime) -> Result<()> {
}
if sepp_out {
- let sepp = scmd.value_of("sep").unwrap(); // we checked before
+ let sepp = scmd.map(|s| s.value_of("sep").unwrap()).unwrap_or("");
writeln!(rt.stdout(), "{}", tags.join(sepp))?;
}