diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2019-12-24 12:38:46 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2019-12-24 13:49:26 +0100 |
commit | 708c7b26b12364434316a5435b01a2c3869bfc6f (patch) | |
tree | fc9647ca0dafcb72d0a52930a1382c3f32b87760 | |
parent | 0cac7ec15774f8381e2c260e37754e17788875f2 (diff) |
Fix: Make "list" default command of imag-tag
The "list" command is advertised as default command for imag-tag. This
commit fixes the implementation so that the binary actually behaves this
way.
For this, the list() function gets a new parameter which tells it
whether there is a subcommand object to be expected in the Runtime.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | bin/core/imag-tag/src/lib.rs | 29 |
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))?; } |