| 66 | } |
| 67 | |
| 68 | func CommentablePreRun(cmd *cobra.Command, opts *CommentableOptions) error { |
| 69 | inputFlags := 0 |
| 70 | if cmd.Flags().Changed("body") { |
| 71 | opts.InputType = InputTypeInline |
| 72 | opts.BodyProvided = true |
| 73 | inputFlags++ |
| 74 | } |
| 75 | if cmd.Flags().Changed("body-file") { |
| 76 | opts.InputType = InputTypeInline |
| 77 | opts.BodyProvided = true |
| 78 | inputFlags++ |
| 79 | } |
| 80 | web, _ := cmd.Flags().GetBool("web") |
| 81 | if web { |
| 82 | opts.InputType = InputTypeWeb |
| 83 | inputFlags++ |
| 84 | } |
| 85 | if editor, _ := cmd.Flags().GetBool("editor"); editor { |
| 86 | opts.InputType = InputTypeEditor |
| 87 | inputFlags++ |
| 88 | } |
| 89 | |
| 90 | if err := cmdutil.MutuallyExclusive( |
| 91 | "`--attach` is not supported when using `--web`", |
| 92 | opts.AttachFlag.Changed(), |
| 93 | web, |
| 94 | ); err != nil { |
| 95 | return err |
| 96 | } |
| 97 | |
| 98 | if err := cmdutil.MutuallyExclusive( |
| 99 | "`--attach` is not supported when using `--delete-last`", |
| 100 | opts.AttachFlag.Changed(), |
| 101 | opts.DeleteLast, |
| 102 | ); err != nil { |
| 103 | return err |
| 104 | } |
| 105 | |
| 106 | resolved, err := opts.AttachFlag.UserAssets() |
| 107 | if err != nil { |
| 108 | return err |
| 109 | } |
| 110 | opts.Assets = resolved |
| 111 | |
| 112 | // An asset is a body input on its own, so `--attach shot.png` alone |
| 113 | // posts an image with no text. It is not part of the mutually exclusive |
| 114 | // group above, so it only counts when nothing else has. |
| 115 | if len(opts.Assets) > 0 && inputFlags == 0 { |
| 116 | opts.InputType = InputTypeInline |
| 117 | inputFlags++ |
| 118 | } |
| 119 | |
| 120 | if opts.CreateIfNone && !opts.EditLast { |
| 121 | return cmdutil.FlagErrorf("`--create-if-none` can only be used with `--edit-last`") |
| 122 | } |
| 123 | |
| 124 | if opts.DeleteLastConfirmed && !opts.DeleteLast { |
| 125 | return cmdutil.FlagErrorf("`--yes` should only be used with `--delete-last`") |