mirror of
https://github.com/dnote/dnote
synced 2026-03-18 08:19:55 +01:00
61 lines
927 B
Go
61 lines
927 B
Go
package notes
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/dnote-io/cli/cmd/root"
|
|
"github.com/dnote-io/cli/utils"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var example = `
|
|
* List notes in the current book
|
|
dnote notes
|
|
dnote ls
|
|
|
|
* List notes in a certain book
|
|
dnote ls javascript
|
|
`
|
|
|
|
var cmd = &cobra.Command{
|
|
Use: "notes <book name?>",
|
|
Aliases: []string{"ls"},
|
|
Short: "List all notes",
|
|
Example: example,
|
|
RunE: run,
|
|
}
|
|
|
|
func init() {
|
|
root.Register(cmd)
|
|
}
|
|
|
|
func run(cmd *cobra.Command, args []string) error {
|
|
var bookName string
|
|
|
|
if len(args) == 1 {
|
|
bookName = args[0]
|
|
} else {
|
|
var err error
|
|
bookName, err = utils.GetCurrentBook()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
fmt.Printf("On note %s\n", bookName)
|
|
|
|
dnote, err := utils.GetDnote()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for k, v := range dnote {
|
|
if k == bookName {
|
|
for i, note := range v {
|
|
fmt.Printf("* [%d] - %s\n", i, note.Content)
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|