MCPcopy
hub / github.com/cli/cli / viewRun

Function viewRun

pkg/cmd/discussion/view/view.go:232–334  ·  view source on GitHub ↗
(opts *ViewOptions)

Source from the content-addressed store, hash-verified

230}
231
232func viewRun(opts *ViewOptions) error {
233 repo, err := opts.BaseRepo()
234 if err != nil {
235 return err
236 }
237
238 c, err := opts.Client()
239 if err != nil {
240 return err
241 }
242
243 repliesMode := opts.CommentNodeID != "" || opts.CommentDatabaseID != 0
244
245 if opts.WebMode {
246 if !repliesMode {
247 openURL := ghrepo.GenerateRepoURL(repo, "discussions/%d", opts.DiscussionNumber)
248 if opts.IO.IsStderrTTY() {
249 fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(openURL))
250 }
251 return opts.Browser.Browse(openURL)
252 }
253
254 opts.IO.StartProgressIndicator()
255 commentID, err := resolveCommentNodeID(c, repo, opts)
256 if err != nil {
257 opts.IO.StopProgressIndicator()
258 return err
259 }
260 comment, err := c.GetComment(repo.RepoHost(), commentID)
261 opts.IO.StopProgressIndicator()
262 if err != nil {
263 return err
264 }
265 if opts.IO.IsStderrTTY() {
266 fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(comment.URL))
267 }
268 return opts.Browser.Browse(comment.URL)
269 }
270
271 opts.IO.DetectTerminalTheme()
272 opts.IO.StartProgressIndicator()
273
274 if repliesMode {
275 commentID, err := resolveCommentNodeID(c, repo, opts)
276 if err != nil {
277 opts.IO.StopProgressIndicator()
278 return err
279 }
280
281 discussion, err := c.GetCommentReplies(repo.RepoHost(), commentID, opts.Limit, opts.After, opts.Order == orderNewest)
282 opts.IO.StopProgressIndicator()
283 if err != nil {
284 return err
285 }
286
287 if opts.Exporter != nil {
288 return opts.Exporter.Write(opts.IO, discussion)
289 }

Callers 2

TestViewRunFunction · 0.70
NewCmdViewFunction · 0.70

Calls 15

GenerateRepoURLFunction · 0.92
DisplayURLFunction · 0.92
resolveCommentNodeIDFunction · 0.85
printRawRepliesFunction · 0.85
needsCommentsFunction · 0.85
printHumanViewFunction · 0.85
printRawCommentsFunction · 0.85
printRawViewFunction · 0.85
IsStderrTTYMethod · 0.80
DetectTerminalThemeMethod · 0.80
StartPagerMethod · 0.80

Tested by 1

TestViewRunFunction · 0.56