MCPcopy Create free account
hub / github.com/cli/cli / viewRun

Function viewRun

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

Source from the content-addressed store, hash-verified

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

Callers 2

Test_viewRunFunction · 0.70
NewCmdViewFunction · 0.70

Calls 15

RawBytesMethod · 0.95
StringMethod · 0.95
RawMethod · 0.95
FlagErrorfFunction · 0.92
PromptGistsFunction · 0.92
GistPrefixFunction · 0.92
DisplayURLFunction · 0.92
GistIDFromURLFunction · 0.92
GetGistFunction · 0.92
NewUntrustedFunction · 0.92
GetRawGistFileFunction · 0.92
NewImmutableSafeURLFunction · 0.92

Tested by 1

Test_viewRunFunction · 0.56