From 54bfbf1886cfe27e1f79fcc6b777a58343dff800 Mon Sep 17 00:00:00 2001 From: Rafael Gumieri Date: Wed, 25 Apr 2018 14:32:49 -0300 Subject: [PATCH] Usage improvements & bug fixes `note` command: - Add flag title as option to define note title `note show` command: - Fix bug when no note is found `note edit` command: - Fix bug when no note is found `note delete` command: - Fix bug when no note is found - Ask for confirmation to delete note - Add flag option yes to delete command --- cmd/deleteNote.go | 5 +++++ cmd/editNote.go | 5 +++++ cmd/showNote.go | 5 +++++ main.go | 2 +- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/deleteNote.go b/cmd/deleteNote.go index 721f1b2..ee94bd0 100644 --- a/cmd/deleteNote.go +++ b/cmd/deleteNote.go @@ -29,6 +29,11 @@ func DeleteNote(context *cli.Context) { noteToFind := strings.Join(context.Args()[:], " ") notesFound := fuzzy.RankFind(noteToFind, notesNames) + + if len(notesFound) == 0 { + os.Exit(1) + } + noteFound := notesFound[0].Target confirmMessage := fmt.Sprintf("Do you want to delete the note %s ?", noteFound) diff --git a/cmd/editNote.go b/cmd/editNote.go index 4457c54..58b5dff 100644 --- a/cmd/editNote.go +++ b/cmd/editNote.go @@ -30,6 +30,11 @@ func EditNote(context *cli.Context) { noteToFind := strings.Join(context.Args()[:], " ") notesFound := fuzzy.RankFind(noteToFind, notesNames) + + if len(notesFound) == 0 { + os.Exit(1) + } + noteFound := notesFound[0].Target err = editor.File(viper.GetString("editor"), filepath.Join(notePath, noteFound)) diff --git a/cmd/showNote.go b/cmd/showNote.go index 9b3a942..fb9e5e6 100644 --- a/cmd/showNote.go +++ b/cmd/showNote.go @@ -29,6 +29,11 @@ func ShowNote(context *cli.Context) { noteToFind := strings.Join(context.Args()[:], " ") notesFound := fuzzy.RankFind(noteToFind, notesNames) + + if len(notesFound) == 0 { + os.Exit(1) + } + noteFound := notesFound[0].Target noteContent, err := ioutil.ReadFile(filepath.Join(notePath, noteFound)) diff --git a/main.go b/main.go index 94da65e..c4e5d2b 100644 --- a/main.go +++ b/main.go @@ -32,7 +32,7 @@ func main() { app.Name = "Note" - app.Version = "0.0.4" + app.Version = "0.0.5" app.Usage = "Quick and easy Command-line tool for taking notes" app.UsageText = "note [just type a text] [or command] [with command options]"