Move cli-name-extracting into helper function
This commit is contained in:
parent
8ee4a7ff50
commit
c7c092be93
1 changed files with 6 additions and 14 deletions
|
@ -53,14 +53,12 @@ fn main() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create(rt: &Runtime) {
|
fn name_from_cli(rt: &Runtime, subcmd: &str) -> String {
|
||||||
let name = rt.cli()
|
rt.cli().subcommand_matches(subcmd).unwrap().value_of("name").map(String::from).unwrap()
|
||||||
.subcommand_matches("create")
|
}
|
||||||
.unwrap() // we already know it is there
|
|
||||||
.value_of("name")
|
|
||||||
.unwrap(); // enforced by clap
|
|
||||||
|
|
||||||
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_err(|e| trace_error(&e))
|
||||||
.map(|note| {
|
.map(|note| {
|
||||||
// call editor now...
|
// call editor now...
|
||||||
|
@ -68,13 +66,7 @@ fn create(rt: &Runtime) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn delete(rt: &Runtime) {
|
fn delete(rt: &Runtime) {
|
||||||
let name = rt.cli()
|
Note::delete(rt.store(), String::from(name_from_cli(rt, "delete")))
|
||||||
.subcommand_matches("delete")
|
|
||||||
.unwrap() // we already know it is there
|
|
||||||
.value_of("name")
|
|
||||||
.unwrap(); // enforced by clap
|
|
||||||
|
|
||||||
Note::delete(rt.store(), String::from(name))
|
|
||||||
.map_err(|e| trace_error(&e))
|
.map_err(|e| trace_error(&e))
|
||||||
.map(|_| println!("Ok"));
|
.map(|_| println!("Ok"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue