Skip to content

Commit

Permalink
Add list as table; Highlight note being deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
gumieri authored and Rafael Gumieri committed May 2, 2018
1 parent 5829bb0 commit ae0d07c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
6 changes: 4 additions & 2 deletions cmd/deleteNote.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path/filepath"

"github.com/fatih/color"
libCli "github.com/gumieri/note/lib/cli"
"github.com/gumieri/note/lib/notes"
"github.com/spf13/viper"
Expand All @@ -23,14 +24,15 @@ func DeleteNote(context *cli.Context) {
os.Exit(1)
}

noteFound, err := notes.FindNoteName(notePath, context.Args()[:])
noteFound, err := notes.FindNoteName(notePath, context.Args())

if err != nil {
fmt.Println(err)
os.Exit(1)
}

confirmMessage := fmt.Sprintf("Do you want to delete the note %s ?", noteFound)
red := color.New(color.FgRed).Add(color.Bold).SprintFunc()
confirmMessage := fmt.Sprintf("note: delete note '%s'?", red(noteFound))
if !context.Bool("yes") && !libCli.Confirm(confirmMessage) {
return
}
Expand Down
6 changes: 2 additions & 4 deletions cmd/editNote.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ func EditNote(context *cli.Context) {

noteTitle := context.String("title")

args := context.Args()[:]

_, err := os.Stat(notePath)

if err != nil {
Expand All @@ -69,9 +67,9 @@ func EditNote(context *cli.Context) {
}

if noteTitle == "" {
err = editContent(notePath, args)
err = editContent(notePath, context.Args())
} else {
err = editTitle(notePath, noteTitle, args)
err = editTitle(notePath, noteTitle, context.Args())
}

if err != nil {
Expand Down
11 changes: 7 additions & 4 deletions cmd/listNotes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"fmt"
"os"

"github.com/fatih/color"
"github.com/gumieri/note/lib/notes"
"github.com/spf13/viper"
"github.com/urfave/cli"

"github.com/gumieri/note/lib/notes"
)

// ListNotes list all existing notes in the NOTE_PATH
Expand All @@ -28,8 +28,11 @@ func ListNotes(context *cli.Context) {
os.Exit(1)
}

for _, note := range notesNames {
fmt.Println(note)
color.New(color.Bold).Println("ID\tTitle")
for _, noteName := range notesNames {
number := notes.NumberFromNoteName(noteName)
title := notes.TitleFromNoteName(noteName)
fmt.Printf("%d\t%s\n", number, title)
}

return
Expand Down
7 changes: 5 additions & 2 deletions cmd/showNote.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func ShowNote(context *cli.Context) {
os.Exit(1)
}

noteFound, err := notes.FindNoteName(notePath, context.Args()[:])
noteFound, err := notes.FindNoteName(notePath, context.Args())

if err != nil {
fmt.Println(err)
Expand All @@ -37,6 +37,9 @@ func ShowNote(context *cli.Context) {
os.Exit(1)
}

fmt.Printf("%s\n\n%s", noteFound, noteContent)
number := notes.NumberFromNoteName(noteFound)
title := notes.TitleFromNoteName(noteFound)

fmt.Printf("%d\t%s\n\n%s", number, title, noteContent)
return
}
6 changes: 4 additions & 2 deletions cmd/writeNote.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func WriteNote(context *cli.Context) {
var noteContent string
if len(context.Args()) == 0 {
editorCommand := viper.GetString("editor")

var tmpTitle string
if noteTitle == "" {
tmpTitle = "new note"
Expand All @@ -59,7 +60,7 @@ func WriteNote(context *cli.Context) {
os.Exit(1)
}
} else {
noteContent = fmt.Sprintf("%s\n", strings.Join(context.Args()[:], " "))
noteContent = fmt.Sprintf("%s\n", strings.Join(context.Args(), " "))
}

if noteContent == "" {
Expand All @@ -80,10 +81,11 @@ func WriteNote(context *cli.Context) {
os.Exit(1)
}

fmt.Println(noteName)
noteFile.WriteString(noteContent)

defer noteFile.Close()

fmt.Printf("%d\t%s\n", nextNumber, noteTitle)

return
}

0 comments on commit ae0d07c

Please sign in to comment.