MCPcopy
hub / github.com/cli/cli / editRun

Function editRun

pkg/cmd/gist/edit/edit.go:117–376  ·  view source on GitHub ↗
(opts *EditOptions)

Source from the content-addressed store, hash-verified

115}
116
117func editRun(opts *EditOptions) error {
118 client, err := opts.HttpClient()
119 if err != nil {
120 return err
121 }
122
123 cfg, err := opts.Config()
124 if err != nil {
125 return err
126 }
127
128 host, _ := cfg.Authentication().DefaultHost()
129
130 gistID := opts.Selector
131 if gistID == "" {
132 cs := opts.IO.ColorScheme()
133 if gistID == "" {
134 if !opts.IO.CanPrompt() {
135 return cmdutil.FlagErrorf("gist ID or URL required when not running interactively")
136 }
137
138 gist, err := shared.PromptGists(opts.Prompter, client, host, cs)
139 if err != nil {
140 return err
141 }
142
143 if gist.ID == "" {
144 fmt.Fprintln(opts.IO.Out, "No gists found.")
145 return nil
146 }
147 gistID = gist.ID
148 }
149 }
150
151 if strings.Contains(gistID, "/") {
152 id, err := shared.GistIDFromURL(gistID)
153 if err != nil {
154 return err
155 }
156 gistID = id
157 }
158
159 apiClient := api.NewClientFromHTTP(client)
160
161 gist, err := shared.GetGist(client, host, gistID)
162 if err != nil {
163 if errors.Is(err, shared.NotFoundErr) {
164 return fmt.Errorf("gist not found: %s", gistID)
165 }
166 return err
167 }
168
169 username, err := api.CurrentLoginName(apiClient, host)
170 if err != nil {
171 return err
172 }
173
174 if username != gist.Owner.Login {

Callers 2

Test_editRunFunction · 0.70
NewCmdEditFunction · 0.70

Calls 15

FlagErrorfFunction · 0.92
PromptGistsFunction · 0.92
GistIDFromURLFunction · 0.92
NewClientFromHTTPFunction · 0.92
GetGistFunction · 0.92
CurrentLoginNameFunction · 0.92
IsBinaryContentsFunction · 0.92
GetRawGistFileFunction · 0.92
DetermineEditorFunction · 0.92
getFilesToAddFunction · 0.85
getFilesToRemoveFunction · 0.85
ColorSchemeMethod · 0.80

Tested by 1

Test_editRunFunction · 0.56