Skip to content

Commit

Permalink
fix output when note not found.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhadfield committed Dec 18, 2023
1 parent 7749887 commit ca734eb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/sncli/note.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,12 @@ func outputNotes(c *cli.Context, count bool, output string, getNoteConfig sncli.
// strip deleted items
rawNotes = sncli.RemoveDeleted(rawNotes)

if len(rawNotes) == 0 {
_, _ = fmt.Fprintf(c.App.Writer, color.Green.Sprintf(msgNoMatches))

return nil
}

var numResults int

var notesYAML []sncli.NoteYAML
Expand Down
14 changes: 14 additions & 0 deletions cmd/sncli/note_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ func TestAddDeleteNote(t *testing.T) {
require.Contains(t, stdout, msgDeleted)
}

func TestGetMissingNote(t *testing.T) {
time.Sleep(1 * time.Second)
var outputBuffer bytes.Buffer
app, err := appSetup()
require.NoError(t, err)
app.Writer = &outputBuffer
osArgs := []string{"sncli", "get", "note", "--title", "missing note"}
err = app.Run(osArgs)
stdout := outputBuffer.String()
fmt.Println(stdout)
require.NoError(t, err)
require.Contains(t, stdout, msgNoMatches)
}

func TestDeleteNonExistantNote(t *testing.T) {
time.Sleep(1 * time.Second)
var outputBuffer bytes.Buffer
Expand Down

0 comments on commit ca734eb

Please sign in to comment.