NewCmd returns a new remove command
(ctx context.DnoteCtx)
| 44 | |
| 45 | // NewCmd returns a new remove command |
| 46 | func NewCmd(ctx context.DnoteCtx) *cobra.Command { |
| 47 | cmd := &cobra.Command{ |
| 48 | Use: "remove <note id|book name>", |
| 49 | Short: "Remove a note or a book", |
| 50 | Aliases: []string{"rm", "d", "delete"}, |
| 51 | Example: example, |
| 52 | PreRunE: preRun, |
| 53 | RunE: newRun(ctx), |
| 54 | } |
| 55 | |
| 56 | f := cmd.Flags() |
| 57 | f.StringVarP(&bookFlag, "book", "b", "", "The book name to delete") |
| 58 | f.BoolVarP(&yesFlag, "yes", "y", false, "Assume yes to the prompts and run in non-interactive mode") |
| 59 | |
| 60 | f.MarkDeprecated("book", "Pass the book name as an argument. e.g. `dnote rm book_name`") |
| 61 | |
| 62 | return cmd |
| 63 | } |
| 64 | |
| 65 | func preRun(cmd *cobra.Command, args []string) error { |
| 66 | if len(args) != 1 && len(args) != 2 { |