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

Function PromptGists

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

Source from the content-addressed store, hash-verified

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