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

Function editRun

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

Source from the content-addressed store, hash-verified

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

Tested by 1

Test_editRunFunction · 0.56