summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-11-13 19:38:39 +0100
committerMatthias Beyer <mail@beyermatthias.de>2019-11-13 19:38:39 +0100
commit9e532f79dd7c5a3fb10c7180b24e4ac913768e3e (patch)
tree31a74040ebcd9f9981dbbe1f5bc1dd7570064514
parent5a89a29b6d3cc9d020006c264e321bcb47553711 (diff)
Transform the main function to get the subcommand object
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--bin/core/imag-tag/src/lib.rs73
1 files changed, 31 insertions, 42 deletions
diff --git a/bin/core/imag-tag/src/lib.rs b/bin/core/imag-tag/src/lib.rs
index 83f58722..3c8767c9 100644
--- a/bin/core/imag-tag/src/lib.rs
+++ b/bin/core/imag-tag/src/lib.rs
@@ -86,51 +86,40 @@ pub enum ImagTag {}
impl ImagApplication for ImagTag {
fn run(rt: Runtime) -> Result<()> {
let process = |iter: &mut dyn Iterator<Item = Result<StoreId>>| -> Result<()> {
- if let Some(name) = rt.cli().subcommand_name() {
- match name {
- "list" => iter
- .map_ok(|id| list(id, &rt))
- .collect::<Result<Vec<_>>>()
- .map(|_| ()),
-
- "remove" => iter.and_then_ok(|id| {
- let add = None;
- let rem = get_remove_tags(rt.cli())?;
- debug!("id = {:?}, add = {:?}, rem = {:?}", id, add, rem);
- alter(&rt, id, add, rem)
- }).collect(),
-
- "add" => iter.and_then_ok(|id| {
- let add = get_add_tags(rt.cli())?;
- let rem = None;
- debug!("id = {:?}, add = {:?}, rem = {:?}", id, add, rem);
- alter(&rt, id, add, rem)
- }).collect(),
-
- other => {
- debug!("Unknown command");
- if rt.handle_unknown_subcommand("imag-tag", other, rt.cli())?.success() {
- Ok(())
- } else {
- Err(format_err!("Subcommand failed"))
- }
- },
- }
- } else {
- Ok(())
+ match rt.cli().subcommand() {
+ ("list", _) => iter
+ .map_ok(|id| list(id, &rt))
+ .collect::<Result<Vec<_>>>()
+ .map(|_| ()),
+
+ ("remove", _) => iter.and_then_ok(|id| {
+ let add = None;
+ let rem = get_remove_tags(rt.cli())?;
+ debug!("id = {:?}, add = {:?}, rem = {:?}", id, add, rem);
+ alter(&rt, id, add, rem)
+ }).collect(),
+
+ ("add", _) => iter.and_then_ok(|id| {
+ let add = get_add_tags(rt.cli())?;
+ let rem = None;
+ debug!("id = {:?}, add = {:?}, rem = {:?}", id, add, rem);
+ alter(&rt, id, add, rem)
+ }).collect(),
+
+ (other, _) => {
+ debug!("Unknown command");
+ if rt.handle_unknown_subcommand("imag-tag", other, rt.cli())?.success() {
+ Ok(())
+ } else {
+ Err(format_err!("Subcommand failed"))
+ }
+ },
}
};
- if rt.ids_from_stdin() {
- debug!("Fetching IDs from stdin...");
- let mut iter = rt.ids::<crate::ui::PathProvider>()?
- .ok_or_else(|| err_msg("No ids supplied"))?
- .into_iter()
- .map(Ok);
-
- process(&mut iter)
- } else {
- process(&mut rt.store().entries()?)
+ match rt.ids::<crate::ui::PathProvider>()? {
+ Some(ids) => process(&mut ids.into_iter().map(Ok)),
+ None => process(&mut rt.store().entries()?),
}
}