Handle unknown subcommands in binaries with Runtime::handle_unknown_subcommand

This commit is contained in:
Matthias Beyer 2018-04-04 17:01:02 +02:00
parent 140624ec52
commit 8c1b4124c0
15 changed files with 97 additions and 31 deletions

View file

@ -57,7 +57,6 @@ use libimagrt::runtime::Runtime;
use libimagrt::setup::generate_runtime_setup; use libimagrt::setup::generate_runtime_setup;
use libimagstore::store::FileLockEntry; use libimagstore::store::FileLockEntry;
use libimagstore::storeid::IntoStoreId; use libimagstore::storeid::IntoStoreId;
use libimagutil::warn_exit::warn_exit;
mod ui; mod ui;
@ -75,7 +74,13 @@ fn main() {
"add" => add(&rt), "add" => add(&rt),
"remove" => remove(&rt), "remove" => remove(&rt),
"list" => list(&rt), "list" => list(&rt),
_ => warn_exit("No commandline call", 1) other => {
debug!("Unknown command");
let _ = rt.handle_unknown_subcommand("imag-annotation", other, rt.cli())
.map_err_trace_exit_unwrap(1)
.code()
.map(std::process::exit);
},
} }
}); });
} }

View file

@ -53,7 +53,6 @@ use libimagentrygps::types::*;
use libimagentrygps::entry::*; use libimagentrygps::entry::*;
use libimagrt::setup::generate_runtime_setup; use libimagrt::setup::generate_runtime_setup;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use libimagutil::warn_exit::warn_exit;
use libimagerror::trace::MapErrTrace; use libimagerror::trace::MapErrTrace;
use libimagerror::exit::ExitUnwrap; use libimagerror::exit::ExitUnwrap;
use libimagerror::io::ToExitCode; use libimagerror::io::ToExitCode;
@ -75,7 +74,13 @@ fn main() {
"add" => add(&rt), "add" => add(&rt),
"remove" => remove(&rt), "remove" => remove(&rt),
"get" => get(&rt), "get" => get(&rt),
_ => warn_exit("No commandline call", 1) other => {
debug!("Unknown command");
let _ = rt.handle_unknown_subcommand("imag-gps", other, rt.cli())
.map_err_trace_exit_unwrap(1)
.code()
.map(::std::process::exit);
}
} }
}); });
} }

View file

@ -104,7 +104,13 @@ fn main() {
"remove" => remove_linking(&rt), "remove" => remove_linking(&rt),
"unlink" => unlink(&rt), "unlink" => unlink(&rt),
"list" => list_linkings(&rt), "list" => list_linkings(&rt),
_ => panic!("BUG"), other => {
debug!("Unknown command");
let _ = rt.handle_unknown_subcommand("imag-link", other, rt.cli())
.map_err_trace_exit_unwrap(1)
.code()
.map(::std::process::exit);
},
} }
}) })
.or_else(|| { .or_else(|| {

View file

@ -67,8 +67,12 @@ fn main() {
match name { match name {
"deref" => deref(&rt), "deref" => deref(&rt),
"remove" => remove(&rt), "remove" => remove(&rt),
_ => { other => {
debug!("Unknown command"); // More error handling debug!("Unknown command");
let _ = rt.handle_unknown_subcommand("imag-ref", other, rt.cli())
.map_err_trace_exit_unwrap(1)
.code()
.map(::std::process::exit);
}, },
}; };
}); });

View file

@ -50,6 +50,7 @@ extern crate libimagutil;
extern crate libimagutil; extern crate libimagutil;
use libimagrt::setup::generate_runtime_setup; use libimagrt::setup::generate_runtime_setup;
use libimagerror::trace::MapErrTrace;
mod create; mod create;
mod delete; mod delete;
@ -92,9 +93,12 @@ fn main() {
"update" => update(&rt), "update" => update(&rt),
"verify" => verify(&rt), "verify" => verify(&rt),
"dump" => dump(&mut rt), "dump" => dump(&mut rt),
_ => { other => {
debug!("Unknown command"); debug!("Unknown command");
// More error handling let _ = rt.handle_unknown_subcommand("imag-store", other, rt.cli())
.map_err_trace_exit_unwrap(1)
.code()
.map(std::process::exit);
}, },
}; };
} else { } else {

View file

@ -86,9 +86,12 @@ fn main() {
debug!("id = {:?}, add = {:?}, rem = {:?}", id, add, rem); debug!("id = {:?}, add = {:?}, rem = {:?}", id, add, rem);
alter(&rt, id, add, rem); alter(&rt, id, add, rem);
}, },
_ => { other => {
error!("Unknown command"); debug!("Unknown command");
::std::process::exit(1) let _ = rt.handle_unknown_subcommand("imag-tag", other, rt.cli())
.map_err_trace_exit_unwrap(1)
.code()
.map(std::process::exit);
}, },
}); });
} }

View file

@ -77,8 +77,12 @@ fn main() {
"collection" => collection(&rt), "collection" => collection(&rt),
"list" => list(&rt), "list" => list(&rt),
"remove" => remove(&rt), "remove" => remove(&rt),
_ => { other => {
debug!("Unknown command"); // More error handling debug!("Unknown command");
let _ = rt.handle_unknown_subcommand("imag-bookmark", other, rt.cli())
.map_err_trace_exit_unwrap(1)
.code()
.map(::std::process::exit);
}, },
} }
}); });

View file

@ -102,8 +102,12 @@ fn main() {
"show" => show(&rt), "show" => show(&rt),
"find" => find(&rt), "find" => find(&rt),
"create" => create(&rt), "create" => create(&rt),
_ => { other => {
error!("Unknown command"); // More error handling debug!("Unknown command");
let _ = rt.handle_unknown_subcommand("imag-contact", other, rt.cli())
.map_err_trace_exit_unwrap(1)
.code()
.map(::std::process::exit);
}, },
} }
}); });

View file

@ -48,6 +48,7 @@ extern crate libimagtimeui;
extern crate libimagutil; extern crate libimagutil;
use libimagrt::setup::generate_runtime_setup; use libimagrt::setup::generate_runtime_setup;
use libimagerror::trace::MapErrTrace;
mod create; mod create;
mod delete; mod delete;
@ -80,8 +81,12 @@ fn main() {
"edit" => edit(&rt), "edit" => edit(&rt),
"list" => list(&rt), "list" => list(&rt),
"view" => view(&rt), "view" => view(&rt),
_ => { other => {
debug!("Unknown command"); // More error handling debug!("Unknown command");
let _ = rt.handle_unknown_subcommand("imag-diary", other, rt.cli())
.map_err_trace_exit_unwrap(1)
.code()
.map(std::process::exit);
}, },
} }
}); });

View file

@ -90,9 +90,12 @@ fn main() {
"status" => today(&rt, true), "status" => today(&rt, true),
"show" => show(&rt), "show" => show(&rt),
"done" => done(&rt), "done" => done(&rt),
_ => { other => {
debug!("Unknown command"); // More error handling debug!("Unknown command");
exit(1) let _ = rt.handle_unknown_subcommand("imag-habit", other, rt.cli())
.map_err_trace_exit_unwrap(1)
.code()
.map(::std::process::exit);
}, },
} }
}) })

View file

@ -72,9 +72,12 @@ fn main() {
if let Some(scmd) = rt.cli() .subcommand_name() { if let Some(scmd) = rt.cli() .subcommand_name() {
match scmd { match scmd {
"show" => show(&rt), "show" => show(&rt),
_ => { other => {
error!("Unknown command"); debug!("Unknown command");
::std::process::exit(1) let _ = rt.handle_unknown_subcommand("imag-log", other, rt.cli())
.map_err_trace_exit_unwrap(1)
.code()
.map(std::process::exit);
}, },
} }
} else { } else {

View file

@ -54,7 +54,13 @@ fn main() {
"import-mail" => import_mail(&rt), "import-mail" => import_mail(&rt),
"list" => list(&rt), "list" => list(&rt),
"mail-store" => mail_store(&rt), "mail-store" => mail_store(&rt),
_ => debug!("Unknown command") // More error handling other => {
debug!("Unknown command");
let _ = rt.handle_unknown_subcommand("imag-mail", other, rt.cli())
.map_err_trace_exit_unwrap(1)
.code()
.map(std::process::exit);
}
} }
}); });
} }

View file

@ -66,8 +66,12 @@ fn main() {
"delete" => delete(&rt), "delete" => delete(&rt),
"edit" => edit(&rt), "edit" => edit(&rt),
"list" => list(&rt), "list" => list(&rt),
_ => { other => {
debug!("Unknown command"); // More error handling debug!("Unknown command");
let _ = rt.handle_unknown_subcommand("imag-notes", other, rt.cli())
.map_err_trace_exit_unwrap(1)
.code()
.map(std::process::exit);
}, },
}; };
}); });

View file

@ -56,6 +56,7 @@ use week::week;
use year::year; use year::year;
use libimagrt::setup::generate_runtime_setup; use libimagrt::setup::generate_runtime_setup;
use libimagerror::trace::MapErrTrace;
fn main() { fn main() {
let version = make_imag_version!(); let version = make_imag_version!();
@ -77,9 +78,12 @@ fn main() {
"track" => track(&rt), "track" => track(&rt),
"week" => week(&rt), "week" => week(&rt),
"year" => year(&rt), "year" => year(&rt),
_ => { other => {
error!("Unknown command"); debug!("Unknown command");
1 rt.handle_unknown_subcommand("imag-timetrack", other, rt.cli())
.map_err_trace_exit_unwrap(1)
.code()
.unwrap_or(0)
}, },
} }
} else { } else {

View file

@ -51,10 +51,16 @@ fn main() {
match rt.cli().subcommand_name() { match rt.cli().subcommand_name() {
Some("tw-hook") => tw_hook(&rt), Some("tw-hook") => tw_hook(&rt),
Some("list") => list(&rt), Some("list") => list(&rt),
Some(other) => {
debug!("Unknown command");
let _ = rt.handle_unknown_subcommand("imag-todo", other, rt.cli())
.map_err_trace_exit_unwrap(1)
.code()
.map(std::process::exit);
}
None => { None => {
warn!("No command"); warn!("No command");
}, },
_ => unreachable!(),
} // end match scmd } // end match scmd
} // end main } // end main