| 79 | } |
| 80 | |
| 81 | func newRun(ctx context.DnoteCtx) infra.RunEFunc { |
| 82 | return func(cmd *cobra.Command, args []string) error { |
| 83 | // DEPRECATED: Remove in 1.0.0 |
| 84 | if bookFlag != "" { |
| 85 | if err := runBook(ctx, bookFlag); err != nil { |
| 86 | return errors.Wrap(err, "removing the book") |
| 87 | } |
| 88 | |
| 89 | return nil |
| 90 | } |
| 91 | |
| 92 | // DEPRECATED: Remove in 1.0.0 |
| 93 | if len(args) == 2 { |
| 94 | log.Plain(log.ColorYellow.Sprintf("DEPRECATED: you no longer need to pass book name to the remove command. e.g. `dnote remove 123`.\n\n")) |
| 95 | |
| 96 | target := args[1] |
| 97 | if err := runNote(ctx, target); err != nil { |
| 98 | return errors.Wrap(err, "removing the note") |
| 99 | } |
| 100 | |
| 101 | return nil |
| 102 | } |
| 103 | |
| 104 | target := args[0] |
| 105 | |
| 106 | if utils.IsNumber(target) { |
| 107 | if err := runNote(ctx, target); err != nil { |
| 108 | return errors.Wrap(err, "removing the note") |
| 109 | } |
| 110 | } else { |
| 111 | if err := runBook(ctx, target); err != nil { |
| 112 | return errors.Wrap(err, "removing the book") |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | return nil |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | func runNote(ctx context.DnoteCtx, rowIDArg string) error { |
| 121 | db := ctx.DB |