diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-03-19 20:22:15 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-03-26 16:43:33 +0100 |
commit | c7c092be93290f1e75e9a473b3240e9b2b27352b (patch) | |
tree | 4f8397831e4a12c75393c63ca6d05ba3c7b7d8e9 /imag-notes/src | |
parent | 8ee4a7ff50960a60af62b916fdb0ea6714205c2b (diff) |
Move cli-name-extracting into helper function
Diffstat (limited to 'imag-notes/src')
-rw-r--r-- | imag-notes/src/main.rs | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/imag-notes/src/main.rs b/imag-notes/src/main.rs index 385a2bcd..5df74057 100644 --- a/imag-notes/src/main.rs +++ b/imag-notes/src/main.rs @@ -53,14 +53,12 @@ fn main() { }); } -fn create(rt: &Runtime) { - let name = rt.cli() - .subcommand_matches("create") - .unwrap() // we already know it is there - .value_of("name") - .unwrap(); // enforced by clap +fn name_from_cli(rt: &Runtime, subcmd: &str) -> String { + rt.cli().subcommand_matches(subcmd).unwrap().value_of("name").map(String::from).unwrap() +} - Note::new(rt.store(), String::from(name), String::new()) +fn create(rt: &Runtime) { + Note::new(rt.store(), String::from(name_from_cli(rt, "create")), String::new()) .map_err(|e| trace_error(&e)) .map(|note| { // call editor now... @@ -68,13 +66,7 @@ fn create(rt: &Runtime) { } fn delete(rt: &Runtime) { - let name = rt.cli() - .subcommand_matches("delete") - .unwrap() // we already know it is there - .value_of("name") - .unwrap(); // enforced by clap - - Note::delete(rt.store(), String::from(name)) + Note::delete(rt.store(), String::from(name_from_cli(rt, "delete"))) .map_err(|e| trace_error(&e)) .map(|_| println!("Ok")); } |