MCPcopy
hub / github.com/cli/cli / NewCmdComment

Function NewCmdComment

pkg/cmd/discussion/comment/comment.go:33–140  ·  view source on GitHub ↗

NewCmdComment returns the "discussion comment" command.

(f *cmdutil.Factory, runF func(*CommentOptions) error)

Source from the content-addressed store, hash-verified

31
32// NewCmdComment returns the "discussion comment" command.
33func NewCmdComment(f *cmdutil.Factory, runF func(*CommentOptions) error) *cobra.Command {
34 opts := &CommentOptions{
35 IO: f.IOStreams,
36 Prompter: f.Prompter,
37 }
38
39 cmd := &cobra.Command{
40 Use: "comment {<number> | <discussion-url> | <comment-id> | <comment-url>} [flags]",
41 Short: "Add, edit, or delete a comment or a reply on a discussion (preview)",
42 Long: heredoc.Docf(`
43 Manage comments or replies on a GitHub discussion.
44
45 The positional argument can be a discussion number or URL (to add a new
46 top-level comment), or a comment node ID or comment URL (to reply, edit,
47 or delete that comment).
48
49 When the argument is a discussion number or URL, the default action is to
50 add a new top-level comment. Likewise, if the argument is a comment URL or ID
51 the default action is to add a reply.
52
53 Use %[1]s--edit%[1]s to update the comment/reply body, or %[1]s--delete%[1]s to remove it.
54
55 The body can be supplied via %[1]s--body%[1]s, %[1]s--body-file%[1]s, or interactively
56 through an editor.
57 `, "`"),
58 Example: heredoc.Doc(`
59 # Add a top-level comment to discussion #123
60 $ gh discussion comment 123 --body 'Thanks'
61
62 # Reply to a comment using its URL
63 $ gh discussion comment 'https://github.com/OWNER/REPO/discussions/123#discussioncomment-456' --body 'Thanks'
64
65 # Reply to a comment using its node ID
66 $ gh discussion comment DC_abc123 --body 'Thanks'
67
68 # Edit a comment/reply
69 $ gh discussion comment 'https://github.com/OWNER/REPO/discussions/123#discussioncomment-456' --edit --body 'Thanks'
70
71 # Delete a comment/reply
72 $ gh discussion comment 'https://github.com/OWNER/REPO/discussions/123#discussioncomment-456' --delete
73
74 # Delete a comment/reply without confirmation prompt
75 $ gh discussion comment 'https://github.com/OWNER/REPO/discussions/123#discussioncomment-456' --delete --yes
76 `),
77 Args: cobra.ExactArgs(1),
78 RunE: func(cmd *cobra.Command, args []string) error {
79 opts.BaseRepo = f.BaseRepo
80 opts.Client = shared.DiscussionClientFunc(f)
81
82 if err := cmdutil.MutuallyExclusive("specify only one of --edit or --delete",
83 cmd.Flags().Changed("edit"), cmd.Flags().Changed("delete")); err != nil {
84 return err
85 }
86 if opts.Delete {
87 if cmd.Flags().Changed("body") || cmd.Flags().Changed("body-file") {
88 return cmdutil.FlagErrorf("--delete cannot be combined with --body or --body-file")
89 }
90 }

Callers 1

TestNewCmdCommentFunction · 0.70

Calls 7

DiscussionClientFuncFunction · 0.92
MutuallyExclusiveFunction · 0.92
FlagErrorfFunction · 0.92
EnableRepoOverrideFunction · 0.92
commentRunFunction · 0.85
CanPromptMethod · 0.80

Tested by 1

TestNewCmdCommentFunction · 0.56