MCPcopy
hub / github.com/dnote/dnote / newRun

Function newRun

pkg/cli/cmd/view/view.go:68–92  ·  view source on GitHub ↗
(ctx context.DnoteCtx)

Source from the content-addressed store, hash-verified

66}
67
68func newRun(ctx context.DnoteCtx) infra.RunEFunc {
69 return func(cmd *cobra.Command, args []string) error {
70 if len(args) == 0 {
71 // List all books
72 return listBooks(ctx, os.Stdout, nameOnly)
73 } else if len(args) == 1 {
74 if nameOnly {
75 return errors.New("--name-only flag is only valid when viewing books")
76 }
77
78 if utils.IsNumber(args[0]) {
79 // View a note by index
80 return viewNote(ctx, os.Stdout, args[0], contentOnly)
81 } else {
82 // List notes in a book
83 return listNotes(ctx, os.Stdout, args[0])
84 }
85 } else if len(args) == 2 {
86 // View a note in a book (book name + note index)
87 return viewNote(ctx, os.Stdout, args[1], contentOnly)
88 }
89
90 return errors.New("Incorrect number of arguments")
91 }
92}

Callers 1

NewCmdFunction · 0.70

Calls 5

IsNumberFunction · 0.92
listBooksFunction · 0.85
viewNoteFunction · 0.85
listNotesFunction · 0.85
NewMethod · 0.80

Tested by

no test coverage detected