diff --git a/README.md b/README.md index 2afde241..f5ea0af9 100644 --- a/README.md +++ b/README.md @@ -1,144 +1,192 @@ -# Dnote CLI - -![Dnote](assets/main.png) - -A command line interface for spontaneously capturing the things you learn while coding - -## Installation - -On macOS, or Linux, run: - - curl -s https://raw.githubusercontent.com/dnote-io/cli/master/install.sh | sh - -In some cases, you might need `sudo`. Feel free to inspect [install.sh](https://github.com/dnote-io/cli/blob/master/install.sh): - - curl -s https://raw.githubusercontent.com/dnote-io/cli/master/install.sh | sudo sh - -On Windows, download [binary](https://github.com/dnote-io/cli/releases) - -## Overview - -Dnote categorizes your **notes** by **books**. - -All your books and notes are stored in `$HOME/.dnote` as a JSON file. - -You can optionally sync your note with Dnote server. Syncing will allow you to interact with your notes using the web frontend at https://dnote.io, and set up digest notifications. - -## Commands - -### dnote use "[book name]" -*alias: u* - -Change the book to write your note in. - -e.g. - - dnote use linux - -### dnote new "[note]" -*alias: n* - -Write a new note under the current book. - -e.g. - - dnote new "set -e instructs bash to exit immediately if any command has non-zero exit status" - -### dnote edit "[note index]" "[content]" -*alias: e* - -Overwrite a note under the current book - -#### Option -*`-b [book name]` - -Specify the name of the book to edit from - -e.g - - $ dnote notes - * [0] - Content index 0. - * [1] - Content index 1. - * [2] - Content index 2. - - $ dnote edit 1 "New content" - [+] Edited Note : 1 - - $ dnote notes - * [0] - Content index 0. - * [1] - New content. - * [2] - Content index 2. - -### dnote delete "[note]" -*alias: d* - -Delete a note under the current book - -#### Option -*`-n [note index]` - -Specify the index of the note to be deleted - -*`-b [book name]` - -Specify the name of the book to be deleted from - -*`--book [book name]` - -e.g. - - $ dnote delete -n [note index] - $ dnote delete -b [book name] [note index] - - -### dnote books -*alias: b* - -List all the books that you created - -e.g. - - $ dnote books - javascript - * linux - tmux - css - -### dnote notes - -List all notes in the current book - -#### Options - -* `-b [book name]` - -Specify the name of the book to read from - -e.g. - - $ dnote notes - On note JS - * .bind() creates a new function - * arrow function uses less memory than function with .bind() - * the time passed to setTimeout is minimum, no guaranteed time - -### dnote sync - -Sync notes with Dnote server - -### dnote login - -Start a login procedure which will store the APIKey to communicate with the server - -## Links - -* [Website](https://dnote.io) -* [Making Dnote (blog article)](https://sungwoncho.io/making-dnote/) - -## License - -MIT - -------- - -> Made by [sung](https://sungwoncho.io) +# Dnote CLI + +![Dnote](assets/main.png) + +A command line interface for spontaneously capturing the things you learn while coding + +## Installation + +On macOS, or Linux, run: + + curl -s https://raw.githubusercontent.com/dnote-io/cli/master/install.sh | sh + +In some cases, you might need `sudo`. Feel free to inspect [install.sh](https://github.com/dnote-io/cli/blob/master/install.sh): + + curl -s https://raw.githubusercontent.com/dnote-io/cli/master/install.sh | sudo sh + +On Windows, download [binary](https://github.com/dnote-io/cli/releases) + +## Overview + +Dnote categorizes your **notes** by **books**. + +All your books and notes are stored in `$HOME/.dnote` as a JSON file. + +You can optionally sync your note with Dnote server. Syncing will allow you to interact with your notes using the web frontend at https://dnote.io, and set up digest notifications. + +## Commands + +### dnote use [book name] +*alias: u* + +Change the book to write your note in. + +e.g. + + dnote use linux + +### dnote new +*alias: n* + +Write a new note. + +#### Usage + +* `dnote new "content"` + +Writes a new note with `content` to the current book. + +* `dnote new [book name] "content"` + +Writes a new note with `content` to the book with the name `[book name]`. + + +e.g. + + dnote new "set -e instructs bash to exit immediately if any command has non-zero exit status" + dnote new linux "Use find - recursively walk the directly." + +### dnote edit +*alias: e* + +Edit a note under the current book + +#### Usage + +* `dnote edit [note index] "[note content]"` + +Edits the note with `note index` in the current book. + +* `dnote edit [book name] [note index] "[note content]"` + +Edits the note with `note index` in the specified book. + +e.g + + $ dnote notes + * [0] - Content index 0. + * [1] - Content index 1. + * [2] - Content index 2. + + $ dnote edit 1 "New content" + [+] Edited Note : 1 + + $ dnote notes + * [0] - Content index 0. + * [1] - New content. + * [2] - Content index 2. + + $ dnote notes linux + * [0] - Linux Content 0 + * [1] - Linux Content 1 + * [2] - Linux Content 2 + + $ dnote edit linux 1 "New Content" + [+] Edited Note : 1 + + $ dnote notes linux + * [0] - Linux Content 0 + * [1] - New Content + * [2] - Linux Content 2 + +### dnote delete +*alias: d* + +Delete either a note or a book + +#### Usage + +* `dnote delete [book name] [index]` + +Deletes the note with `index` in the specified book. + +* `dnote delete -b [book name]` + +Deletes the book with the `book name`. + +e.g + + $ dnote notes JS + * [0] - Content 0. + * [1] - Content 1. + * [2] - Content 2. + + $ dnote delete JS 1 + [+] Edited Note : 1 + + $ dnote notes + * [0] - Content 0. + * [1] - Content 2. + + $ dnote books + JS + linux + Go + + $ dnote delete -b JS + $ dnote books + linux + Go + + +### dnote books +*alias: b* + +List all the books that you created + +e.g. + + $ dnote books + javascript + * linux + tmux + css + +### dnote notes + +List all notes in the current book + +#### Options + +* `-b [book name]` + +Specify the name of the book to read from + +e.g. + + $ dnote notes + On note JS + * .bind() creates a new function + * arrow function uses less memory than function with .bind() + * the time passed to setTimeout is minimum, no guaranteed time + +### dnote sync + +Sync notes with Dnote server + +### dnote login + +Start a login procedure which will store the APIKey to communicate with the server + +## Links + +* [Website](https://dnote.io) +* [Making Dnote (blog article)](https://sungwoncho.io/making-dnote/) + +## License + +MIT + +------- + +> Made by [sung](https://sungwoncho.io) diff --git a/cmd/new/new.go b/cmd/new/new.go index 33b0f82d..43076a20 100644 --- a/cmd/new/new.go +++ b/cmd/new/new.go @@ -7,19 +7,14 @@ import ( "github.com/dnote-io/cli/utils" ) -func Run(content string) error { - currentBook, err := utils.GetCurrentBook() - if err != nil { - return err - } - +func Run(bookName string, content string) error { note := makeNote(content) - err = writeNote(note) + err := writeNote(bookName, note) if err != nil { return err } - fmt.Printf("[+] Added to %s\n", currentBook) + fmt.Printf("[+] Added to %s\n", bookName) return nil } @@ -31,21 +26,16 @@ func makeNote(content string) utils.Note { } } -func writeNote(note utils.Note) error { +func writeNote(bookName string, note utils.Note) error { dnote, err := utils.GetDnote() if err != nil { return err } - book, err := utils.GetCurrentBook() - if err != nil { - return err - } - - if _, ok := dnote[book]; ok { - dnote[book] = append(dnote[book], note) + if _, ok := dnote[bookName]; ok { + dnote[bookName] = append(dnote[bookName], note) } else { - dnote[book] = []utils.Note{note} + dnote[bookName] = []utils.Note{note} } err = utils.WriteDnote(dnote) diff --git a/main.go b/main.go index 7a3fd428..4593ff04 100644 --- a/main.go +++ b/main.go @@ -130,8 +130,21 @@ func main() { err := changeBook(book) check(err) case "new", "n": - note := os.Args[2] - err := new.Run(note) + var note string + var book string + + if len(os.Args) == 3 { + currentBook, err := utils.GetCurrentBook() + if err != nil { + check(err) + } + note = os.Args[2] + book = currentBook + } else if len(os.Args) == 4 { + book = os.Args[2] + note = os.Args[3] + } + err := new.Run(book, note) check(err) case "edit", "e": err := edit.Edit()