mirror of
https://github.com/dnote/dnote
synced 2026-03-15 23:15:50 +01:00
* Migrate uuids of books that already exist in server * Remove actions * Add dirty flag for notes and books * Drop actions table * Implement sync * Add debug * Update uuid after posting resources to the server * Fix dev script
60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
package view
|
|
|
|
import (
|
|
"github.com/dnote/cli/core"
|
|
"github.com/dnote/cli/infra"
|
|
"github.com/pkg/errors"
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/dnote/cli/cmd/cat"
|
|
"github.com/dnote/cli/cmd/ls"
|
|
)
|
|
|
|
var example = `
|
|
* View all books
|
|
dnote view
|
|
|
|
* List notes in a book
|
|
dnote view javascript
|
|
|
|
* View a particular note in a book
|
|
dnote view javascript 0
|
|
`
|
|
|
|
func preRun(cmd *cobra.Command, args []string) error {
|
|
if len(args) > 2 {
|
|
return errors.New("Incorrect number of argument")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// NewCmd returns a new view command
|
|
func NewCmd(ctx infra.DnoteCtx) *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "view <book name?> <note index?>",
|
|
Aliases: []string{"v"},
|
|
Short: "List books, notes or view a content",
|
|
Example: example,
|
|
RunE: newRun(ctx),
|
|
PreRunE: preRun,
|
|
}
|
|
|
|
return cmd
|
|
}
|
|
|
|
func newRun(ctx infra.DnoteCtx) core.RunEFunc {
|
|
return func(cmd *cobra.Command, args []string) error {
|
|
var run core.RunEFunc
|
|
|
|
if len(args) <= 1 {
|
|
run = ls.NewRun(ctx)
|
|
} else if len(args) == 2 {
|
|
run = cat.NewRun(ctx)
|
|
} else {
|
|
return errors.New("Incorrect number of arguments")
|
|
}
|
|
|
|
return run(cmd, args)
|
|
}
|
|
}
|