| 66 | } |
| 67 | |
| 68 | func 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 | } |