Skip to content

Commit

Permalink
Merge pull request #3 from MeztliRA/clear
Browse files Browse the repository at this point in the history
Added function to delete all notes
  • Loading branch information
MeztliRA authored Apr 9, 2021
2 parents 108405b + 7f528b8 commit ce4db76
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
19 changes: 19 additions & 0 deletions file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

note "github.com/MeztliRA/gemdot/notes"
"github.com/MeztliRA/yon"
)

func View(notes []string) {
Expand Down Expand Up @@ -81,6 +82,24 @@ func Delete(notes []string) []string {
}
}

func Clear() ([]string, bool) {
var (
notes []string
cleared bool
)

response := yon.Prompt("\nare you sure you want to delete all your note")
if response == yon.Yes {
fmt.Println("\nall notes deleted!")
cleared = true
return notes, cleared
} else {
fmt.Println("\ncancelled...")
cleared = false
return notes, cleared
}
}

func Overwrite(notes []string) {
jsonData, err := json.MarshalIndent(notes, "", " ")
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ module github.com/MeztliRA/gemdot

go 1.16

require github.com/mitchellh/go-homedir v1.1.0
require (
github.com/MeztliRA/yon v1.2.1
github.com/mitchellh/go-homedir v1.1.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
github.com/MeztliRA/yon v1.2.1 h1:DqJP1qceSxoxfKqEqwEUfpWlqDe8/9CFKwxaSWQsUqA=
github.com/MeztliRA/yon v1.2.1/go.mod h1:mFYWxCIiuNqL8PbtDAr9D3t2N+A2ngXeonSs80dwOIQ=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func main() {

L:
for {
fmt.Print("what do you want to do(view, add, delete) ")
fmt.Print("what do you want to do(view, add, delete, clear) ")
response, err := reader.ReadString('\n')
if err != nil {
log.Fatal(err)
Expand All @@ -69,6 +69,12 @@ L:
notes = files.Delete(notes)
files.Overwrite(notes)
break L
case "Clear", "clear", "CLEAR":
notesGet, cleared := files.Clear()
if cleared {
files.Overwrite(notesGet)
}
break L
default:
fmt.Println("unknown action")
continue
Expand Down

0 comments on commit ce4db76

Please sign in to comment.