| 73 | } |
| 74 | |
| 75 | func newRun(ctx context.DnoteCtx) infra.RunEFunc { |
| 76 | return func(cmd *cobra.Command, args []string) error { |
| 77 | // DEPRECATED: Remove in 1.0.0 |
| 78 | if len(args) == 2 { |
| 79 | log.Plain(log.ColorYellow.Sprintf("DEPRECATED: you no longer need to pass book name to the view command. e.g. `dnote view 123`.\n\n")) |
| 80 | |
| 81 | target := args[1] |
| 82 | |
| 83 | if err := runNote(ctx, target); err != nil { |
| 84 | return errors.Wrap(err, "editing note") |
| 85 | } |
| 86 | |
| 87 | return nil |
| 88 | } |
| 89 | |
| 90 | target := args[0] |
| 91 | |
| 92 | if utils.IsNumber(target) { |
| 93 | if err := runNote(ctx, target); err != nil { |
| 94 | return errors.Wrap(err, "editing note") |
| 95 | } |
| 96 | } else { |
| 97 | if err := runBook(ctx, target); err != nil { |
| 98 | return errors.Wrap(err, "editing book") |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | return nil |
| 103 | } |
| 104 | } |