dnote/cmd/view/view.go
Sung Won Cho fa1da50fc5
Implement state-based sync (#144)
* 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
2018-12-02 11:04:16 +10:00

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)
}
}