(cmd *cobra.Command, opts *CommentableOptions)
| 56 | } |
| 57 | |
| 58 | func CommentablePreRun(cmd *cobra.Command, opts *CommentableOptions) error { |
| 59 | inputFlags := 0 |
| 60 | if cmd.Flags().Changed("body") { |
| 61 | opts.InputType = InputTypeInline |
| 62 | inputFlags++ |
| 63 | } |
| 64 | if cmd.Flags().Changed("body-file") { |
| 65 | opts.InputType = InputTypeInline |
| 66 | inputFlags++ |
| 67 | } |
| 68 | if web, _ := cmd.Flags().GetBool("web"); web { |
| 69 | opts.InputType = InputTypeWeb |
| 70 | inputFlags++ |
| 71 | } |
| 72 | if editor, _ := cmd.Flags().GetBool("editor"); editor { |
| 73 | opts.InputType = InputTypeEditor |
| 74 | inputFlags++ |
| 75 | } |
| 76 | |
| 77 | if opts.CreateIfNone && !opts.EditLast { |
| 78 | return cmdutil.FlagErrorf("`--create-if-none` can only be used with `--edit-last`") |
| 79 | } |
| 80 | |
| 81 | if opts.DeleteLastConfirmed && !opts.DeleteLast { |
| 82 | return cmdutil.FlagErrorf("`--yes` should only be used with `--delete-last`") |
| 83 | } |
| 84 | |
| 85 | if opts.DeleteLast { |
| 86 | if inputFlags > 0 { |
| 87 | return cmdutil.FlagErrorf("should not provide comment body when using `--delete-last`") |
| 88 | } |
| 89 | if opts.IO.CanPrompt() || opts.DeleteLastConfirmed { |
| 90 | opts.Interactive = opts.IO.CanPrompt() |
| 91 | return nil |
| 92 | } |
| 93 | return cmdutil.FlagErrorf("should provide `--yes` to confirm deletion in non-interactive mode") |
| 94 | } |
| 95 | |
| 96 | if inputFlags == 0 { |
| 97 | if !opts.IO.CanPrompt() { |
| 98 | return cmdutil.FlagErrorf("flags required when not running interactively") |
| 99 | } |
| 100 | opts.Interactive = true |
| 101 | } else if inputFlags > 1 { |
| 102 | return cmdutil.FlagErrorf("specify only one of `--body`, `--body-file`, `--editor`, or `--web`") |
| 103 | } |
| 104 | |
| 105 | return nil |
| 106 | } |
| 107 | |
| 108 | func CommentableRun(opts *CommentableOptions) error { |
| 109 | commentable, repo, err := opts.RetrieveCommentable() |
no test coverage detected