mirror of
https://github.com/dnote/dnote
synced 2026-03-14 22:45:50 +01:00
use now creates a new book entry in the Dnote file.
This commit is contained in:
parent
910b21db4e
commit
941aafc962
3 changed files with 38 additions and 13 deletions
|
|
@ -1,9 +1,7 @@
|
|||
package new
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"time"
|
||||
|
||||
"github.com/dnote-io/cli/utils"
|
||||
|
|
@ -50,17 +48,7 @@ func writeNote(note utils.Note) error {
|
|||
dnote[book] = []utils.Note{note}
|
||||
}
|
||||
|
||||
d, err := json.MarshalIndent(dnote, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
notePath, err := utils.GetDnotePath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(notePath, d, 0644)
|
||||
err := utils.WriteDnote(dnote)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
15
main.go
15
main.go
|
|
@ -75,6 +75,21 @@ func changeBook(bookName string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Now add this book to the .dnote file, for issue #2
|
||||
dnote, err := utils.GetDnote()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, exists := dnote[bookName]
|
||||
if exists == false {
|
||||
dnote[bookName] = make([]utils.Note, 0)
|
||||
err := utils.WriteDnote(dnote)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("Now using %s\n", bookName)
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/dnote-io/cli/utils"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
|
|
@ -167,6 +169,26 @@ func GetDnote() (Dnote, error) {
|
|||
return ret, nil
|
||||
}
|
||||
|
||||
// WriteDnote persists the state of Dnote into the dnote file
|
||||
func WriteDnote(dnote Dnote) error {
|
||||
d, err := json.MarshalIndent(dnote, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
notePath, err := utils.GetDnotePath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(notePath, d, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Deprecated. See upgrade/upgrade.go
|
||||
func GetNote() (YAMLDnote, error) {
|
||||
ret := YAMLDnote{}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue