Skip to content

Commit

Permalink
Add notebook optional restriction to delete cmd
Browse files Browse the repository at this point in the history
By using the -b or --notebook flag, the delete
command will only search within the given
notebook.
  • Loading branch information
TcM1911 committed Dec 30, 2016
1 parent 31d366b commit 3f4635d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
8 changes: 7 additions & 1 deletion cmd/deleteNote.go.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@ To expunge the note you need to use the official client or the web client.`,
fmt.Println("Error, a note title has to be given")
return
}
evernote.DeleteNote(args[0])
nb, err := cmd.Flags().GetString("notebook")
if err != nil {
fmt.Println("Error when parsing the notebook name:", err)
return
}
evernote.DeleteNote(args[0], nb)
},
}

func init() {
noteCmd.AddCommand(deleteNoteCmd)
deleteNoteCmd.Flags().StringP("notebook", "b", "", "The notebook of the note.")
}
25 changes: 18 additions & 7 deletions evernote/note.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,21 @@ type Note struct {
Notebook *Notebook
}

// GetNote gets the note metadata from the server.
func GetNote(title string) *Note {
// GetNote gets the note metadata in the notebook from the server.
// If the notebook is an empty string, the first matching note will
// be returned.
func GetNote(title, notebook string) *Note {
ns := user.GetNoteStore()
filter := notestore.NewNoteFilter()
if notebook != "" {
nb, err := findNotebook(notebook)
if err != nil {
fmt.Println("Error when getting the notebook:", err)
os.Exit(1)
}
nbGUID := nb.GetGUID()
filter.NotebookGuid = &nbGUID
}
filter.Words = &title
notes, err := ns.FindNotes(user.AuthToken, filter, 0, 20)
if err != nil {
Expand Down Expand Up @@ -106,7 +117,7 @@ func convert(note *types.Note) *Note {

// GetNoteWithContent returns the note with content from the user's notestore.
func GetNoteWithContent(title string) *Note {
n := GetNote(title)
n := GetNote(title, "")
ns := user.GetNoteStore()
content, err := ns.GetNoteContent(user.AuthToken, n.GUID)
if err != nil {
Expand All @@ -124,13 +135,13 @@ func SaveChanges(n *Note) {
}

func ChangeTitle(old, new string) {
n := GetNote(old)
n := GetNote(old, "")
n.Title = new
saveChanges(n, false)
}

func MoveNote(noteTitle, notebookName string) {
n := GetNote(noteTitle)
n := GetNote(noteTitle, "")
b, err := FindNotebook(notebookName)
if err != nil {
fmt.Println("Error when trying to retrieve notebook:", err)
Expand All @@ -140,8 +151,8 @@ func MoveNote(noteTitle, notebookName string) {
saveChanges(n, false)
}

func DeleteNote(title string) {
n := GetNote(title)
func DeleteNote(title, notebook string) {
n := GetNote(title, notebook)
ns := user.GetNoteStore()
_, err := ns.DeleteNote(user.AuthToken, n.GUID)
if err != nil {
Expand Down

0 comments on commit 3f4635d

Please sign in to comment.