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

Function PromptGists

pkg/cmd/gist/shared/shared.go:225–250  ·  view source on GitHub ↗
(prompter prompter.Prompter, client *http.Client, host string, cs *iostreams.ColorScheme)

Source from the content-addressed store, hash-verified

223}
224
225func PromptGists(prompter prompter.Prompter, client *http.Client, host string, cs *iostreams.ColorScheme) (gist *Gist, err error) {
226 gists, err := ListGists(client, host, 10, nil, false, "all")
227 if err != nil {
228 return &Gist{}, err
229 }
230
231 if len(gists) == 0 {
232 return &Gist{}, nil
233 }
234
235 var opts = make([]string, len(gists))
236
237 for i, gist := range gists {
238 gistTime := text.FuzzyAgo(time.Now(), gist.UpdatedAt)
239 // TODO: support dynamic maxWidth
240 opts[i] = fmt.Sprintf("%s %s %s", cs.Bold(gist.Filename()), gist.TruncDescription(), cs.Muted(gistTime))
241 }
242
243 result, err := prompter.Select("Select a gist", "", opts)
244
245 if err != nil {
246 return &Gist{}, err
247 }
248
249 return &gists[result], nil
250}
251
252// GetRawGistFile fetches the full content of a gist file from its raw URL. The
253// bytes are external content, so they are returned as iostreams.Untrusted to

Callers 4

deleteRunFunction · 0.92
viewRunFunction · 0.92
editRunFunction · 0.92
TestPromptGistsFunction · 0.85

Calls 7

FuzzyAgoFunction · 0.92
ListGistsFunction · 0.85
BoldMethod · 0.80
FilenameMethod · 0.80
TruncDescriptionMethod · 0.80
MutedMethod · 0.80
SelectMethod · 0.65

Tested by 1

TestPromptGistsFunction · 0.68