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

Function viewRun

pkg/cmd/gist/view/view.go:76–221  ·  view source on GitHub ↗
(opts *ViewOptions)

Source from the content-addressed store, hash-verified

74}
75
76func viewRun(opts *ViewOptions) error {
77 gistID := opts.Selector
78 client, err := opts.HttpClient()
79 if err != nil {
80 return err
81 }
82
83 cfg, err := opts.Config()
84 if err != nil {
85 return err
86 }
87
88 hostname, _ := cfg.Authentication().DefaultHost()
89
90 cs := opts.IO.ColorScheme()
91 if gistID == "" {
92 if !opts.IO.CanPrompt() {
93 return cmdutil.FlagErrorf("gist ID or URL required when not running interactively")
94 }
95
96 gist, err := shared.PromptGists(opts.Prompter, client, hostname, cs)
97 if err != nil {
98 return err
99 }
100
101 if gist.ID == "" {
102 fmt.Fprintln(opts.IO.Out, "No gists found.")
103 return nil
104 }
105 gistID = gist.ID
106 }
107
108 if opts.Web {
109 gistURL := gistID
110 if !strings.Contains(gistURL, "/") {
111 gistURL = ghinstance.GistPrefix(hostname) + gistID
112 }
113 if opts.IO.IsStderrTTY() {
114 fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(gistURL))
115 }
116 return opts.Browser.Browse(gistURL)
117 }
118
119 if strings.Contains(gistID, "/") {
120 id, err := shared.GistIDFromURL(gistID)
121 if err != nil {
122 return err
123 }
124 gistID = id
125 }
126
127 gist, err := shared.GetGist(client, hostname, gistID)
128 if err != nil {
129 return err
130 }
131
132 opts.IO.DetectTerminalTheme()
133 if err := opts.IO.StartPager(); err != nil {

Callers 2

Test_viewRunFunction · 0.70
NewCmdViewFunction · 0.70

Calls 15

FlagErrorfFunction · 0.92
PromptGistsFunction · 0.92
GistPrefixFunction · 0.92
DisplayURLFunction · 0.92
GistIDFromURLFunction · 0.92
GetGistFunction · 0.92
GetRawGistFileFunction · 0.92
IsBinaryContentsFunction · 0.92
RenderFunction · 0.92
WithThemeFunction · 0.92
WithWrapFunction · 0.92
ColorSchemeMethod · 0.80

Tested by 1

Test_viewRunFunction · 0.56