NewCmd returns a new edit command
(ctx context.DnoteCtx)
| 47 | |
| 48 | // NewCmd returns a new edit command |
| 49 | func NewCmd(ctx context.DnoteCtx) *cobra.Command { |
| 50 | cmd := &cobra.Command{ |
| 51 | Use: "edit <note id|book name>", |
| 52 | Short: "Edit a note or a book", |
| 53 | Aliases: []string{"e"}, |
| 54 | Example: example, |
| 55 | PreRunE: preRun, |
| 56 | RunE: newRun(ctx), |
| 57 | } |
| 58 | |
| 59 | f := cmd.Flags() |
| 60 | f.StringVarP(&contentFlag, "content", "c", "", "a new content for the note") |
| 61 | f.StringVarP(&bookFlag, "book", "b", "", "the name of the book to move the note to") |
| 62 | f.StringVarP(&nameFlag, "name", "n", "", "a new name for a book") |
| 63 | |
| 64 | return cmd |
| 65 | } |
| 66 | |
| 67 | func preRun(cmd *cobra.Command, args []string) error { |
| 68 | if len(args) != 1 && len(args) != 2 { |