MCPcopy
hub / github.com/cli/cli / NewCmdView

Function NewCmdView

pkg/cmd/discussion/view/view.go:96–214  ·  view source on GitHub ↗

NewCmdView creates the "discussion view" command.

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

Source from the content-addressed store, hash-verified

94
95// NewCmdView creates the "discussion view" command.
96func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Command {
97 opts := &ViewOptions{
98 IO: f.IOStreams,
99 Browser: f.Browser,
100 Now: time.Now,
101 }
102
103 cmd := &cobra.Command{
104 Use: "view {<number> | <discussion-url> | <comment-id> | <comment-url>} [flags]",
105 Short: "View a discussion (preview)",
106 Long: heredoc.Docf(`
107 Display the title, body, and other information about a discussion.
108
109 To see the comments on a discussion, pass %[1]s--comments%[1]s. A few latest replies
110 of each comment will also be retrieved regardless of the selected ordering.
111
112 To see the full reply thread of a single comment, pass a comment node ID or
113 comment URL as the argument instead of a discussion
114 (e.g., %[1]shttps://github.com/OWNER/REPO/discussions/123#discussioncomment-456%[1]s).
115
116 Pagination and ordering can be controlled via %[1]s--order%[1]s, %[1]s--limit%[1]s, and %[1]s--after%[1]s flags.
117
118 Use %[1]s--web%[1]s to open the discussion or comment in a web browser instead.
119 `, "`"),
120 Example: heredoc.Doc(`
121 # View a discussion by number
122 $ gh discussion view 123
123
124 # View a discussion by URL
125 $ gh discussion view https://github.com/OWNER/REPO/discussions/123
126
127 # View with comments
128 $ gh discussion view 123 --comments
129
130 # View with oldest comments first
131 $ gh discussion view 123 --comments --order oldest
132
133 # Limit to 10 comments
134 $ gh discussion view 123 --comments --limit 10
135
136 # Fetch the next page of comments
137 $ gh discussion view 123 --comments --after CURSOR
138
139 # View the reply thread of a comment by node ID
140 $ gh discussion view DC_abc123
141
142 # View the reply thread of a comment by URL
143 $ gh discussion view 'https://github.com/OWNER/REPO/discussions/123#discussioncomment-456'
144
145 # Paginate through replies
146 $ gh discussion view DC_abc123 --limit 10 --after CURSOR
147
148 # Open in browser
149 $ gh discussion view 123 --web
150 `),
151 Args: cobra.ExactArgs(1),
152 RunE: func(cmd *cobra.Command, args []string) error {
153 opts.BaseRepo = f.BaseRepo

Callers 1

TestNewCmdViewFunction · 0.70

Calls 10

MutuallyExclusiveFunction · 0.92
FlagErrorWrapFunction · 0.92
FlagErrorfFunction · 0.92
DiscussionClientFuncFunction · 0.92
EnableRepoOverrideFunction · 0.92
StringEnumFlagFunction · 0.92
AddJSONFlagsFunction · 0.92
needsCommentsFunction · 0.85
viewRunFunction · 0.70

Tested by 1

TestNewCmdViewFunction · 0.56