Add option to edit after creating
This commit is contained in:
parent
272243a125
commit
15dc163504
2 changed files with 29 additions and 12 deletions
|
@ -59,12 +59,16 @@ fn name_from_cli(rt: &Runtime, subcmd: &str) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create(rt: &Runtime) {
|
fn create(rt: &Runtime) {
|
||||||
Note::new(rt.store(), String::from(name_from_cli(rt, "create")), String::new())
|
let name = name_from_cli(rt, "create");
|
||||||
|
Note::new(rt.store(), name.clone(), String::new())
|
||||||
.map_err(|e| trace_error(&e))
|
.map_err(|e| trace_error(&e))
|
||||||
.map(|_| {
|
|
||||||
// call editor now...
|
|
||||||
})
|
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
|
if rt.cli().subcommand_matches("create").unwrap().is_present("edit") {
|
||||||
|
if !edit_entry(rt, name) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn delete(rt: &Runtime) {
|
fn delete(rt: &Runtime) {
|
||||||
|
@ -75,18 +79,24 @@ fn delete(rt: &Runtime) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn edit(rt: &Runtime) {
|
fn edit(rt: &Runtime) {
|
||||||
let note = Note::retrieve(rt.store(), name_from_cli(rt, "edit"));
|
edit_entry(rt, name_from_cli(rt, "edit"));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn edit_entry(rt: &Runtime, name: String) -> bool {
|
||||||
|
let note = Note::retrieve(rt.store(), name);
|
||||||
if note.is_err() {
|
if note.is_err() {
|
||||||
trace_error(¬e.err().unwrap());
|
trace_error(¬e.err().unwrap());
|
||||||
warn!("Cannot edit nonexistent Note");
|
warn!("Cannot edit nonexistent Note");
|
||||||
} else {
|
return false
|
||||||
let mut note = note.unwrap();
|
|
||||||
if let Err(e) = note.edit_content(rt) {
|
|
||||||
trace_error(&e);
|
|
||||||
warn!("Editing failed");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut note = note.unwrap();
|
||||||
|
if let Err(e) = note.edit_content(rt) {
|
||||||
|
trace_error(&e);
|
||||||
|
warn!("Editing failed");
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list(rt: &Runtime) {
|
fn list(rt: &Runtime) {
|
||||||
|
|
|
@ -13,7 +13,14 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
||||||
.short("n")
|
.short("n")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.required(true)
|
.required(true)
|
||||||
.help("Create Note with this name")))
|
.help("Create Note with this name"))
|
||||||
|
.arg(Arg::with_name("edit")
|
||||||
|
.long("edit")
|
||||||
|
.short("e")
|
||||||
|
.takes_value(false)
|
||||||
|
.required(false)
|
||||||
|
.help("Edit after creating"))
|
||||||
|
)
|
||||||
|
|
||||||
.subcommand(SubCommand::with_name("delete")
|
.subcommand(SubCommand::with_name("delete")
|
||||||
.about("Delete a Note")
|
.about("Delete a Note")
|
||||||
|
|
Loading…
Reference in a new issue