Skip to content

Commit 3f4635d

Browse files
committed
Add notebook optional restriction to delete cmd
By using the -b or --notebook flag, the delete command will only search within the given notebook.
1 parent 31d366b commit 3f4635d

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

cmd/deleteNote.go.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,16 @@ To expunge the note you need to use the official client or the web client.`,
3434
fmt.Println("Error, a note title has to be given")
3535
return
3636
}
37-
evernote.DeleteNote(args[0])
37+
nb, err := cmd.Flags().GetString("notebook")
38+
if err != nil {
39+
fmt.Println("Error when parsing the notebook name:", err)
40+
return
41+
}
42+
evernote.DeleteNote(args[0], nb)
3843
},
3944
}
4045

4146
func init() {
4247
noteCmd.AddCommand(deleteNoteCmd)
48+
deleteNoteCmd.Flags().StringP("notebook", "b", "", "The notebook of the note.")
4349
}

evernote/note.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,21 @@ type Note struct {
6565
Notebook *Notebook
6666
}
6767

68-
// GetNote gets the note metadata from the server.
69-
func GetNote(title string) *Note {
68+
// GetNote gets the note metadata in the notebook from the server.
69+
// If the notebook is an empty string, the first matching note will
70+
// be returned.
71+
func GetNote(title, notebook string) *Note {
7072
ns := user.GetNoteStore()
7173
filter := notestore.NewNoteFilter()
74+
if notebook != "" {
75+
nb, err := findNotebook(notebook)
76+
if err != nil {
77+
fmt.Println("Error when getting the notebook:", err)
78+
os.Exit(1)
79+
}
80+
nbGUID := nb.GetGUID()
81+
filter.NotebookGuid = &nbGUID
82+
}
7283
filter.Words = &title
7384
notes, err := ns.FindNotes(user.AuthToken, filter, 0, 20)
7485
if err != nil {
@@ -106,7 +117,7 @@ func convert(note *types.Note) *Note {
106117

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

126137
func ChangeTitle(old, new string) {
127-
n := GetNote(old)
138+
n := GetNote(old, "")
128139
n.Title = new
129140
saveChanges(n, false)
130141
}
131142

132143
func MoveNote(noteTitle, notebookName string) {
133-
n := GetNote(noteTitle)
144+
n := GetNote(noteTitle, "")
134145
b, err := FindNotebook(notebookName)
135146
if err != nil {
136147
fmt.Println("Error when trying to retrieve notebook:", err)
@@ -140,8 +151,8 @@ func MoveNote(noteTitle, notebookName string) {
140151
saveChanges(n, false)
141152
}
142153

143-
func DeleteNote(title string) {
144-
n := GetNote(title)
154+
func DeleteNote(title, notebook string) {
155+
n := GetNote(title, notebook)
145156
ns := user.GetNoteStore()
146157
_, err := ns.DeleteNote(user.AuthToken, n.GUID)
147158
if err != nil {

0 commit comments

Comments
 (0)