MCPcopy
hub / github.com/cli/cli / listRun

Function listRun

pkg/cmd/cache/list/list.go:90–143  ·  view source on GitHub ↗
(opts *ListOptions)

Source from the content-addressed store, hash-verified

88}
89
90func listRun(opts *ListOptions) error {
91 repo, err := opts.BaseRepo()
92 if err != nil {
93 return err
94 }
95
96 httpClient, err := opts.HttpClient()
97 if err != nil {
98 return err
99 }
100 client := api.NewClientFromHTTP(httpClient)
101
102 cs := opts.IO.ColorScheme()
103 opts.IO.StartProgressIndicator()
104 result, err := shared.GetCaches(client, repo, shared.GetCachesOptions{Limit: opts.Limit, Sort: opts.Sort, Order: opts.Order, Key: opts.Key, Ref: opts.Ref})
105 opts.IO.StopProgressIndicator()
106 if err != nil {
107 return fmt.Errorf("%s Failed to get caches: %w", cs.FailureIcon(), err)
108 }
109
110 if len(result.ActionsCaches) == 0 && opts.Exporter == nil {
111 return cmdutil.NewNoResultsError(fmt.Sprintf("No caches found in %s", ghrepo.FullName(repo)))
112 }
113
114 if err := opts.IO.StartPager(); err == nil {
115 defer opts.IO.StopPager()
116 } else {
117 fmt.Fprintf(opts.IO.Out, "Failed to start pager: %v\n", err)
118 }
119
120 if opts.Exporter != nil {
121 return opts.Exporter.Write(opts.IO, result.ActionsCaches)
122 }
123
124 if opts.IO.IsStdoutTTY() {
125 fmt.Fprintf(opts.IO.Out, "\nShowing %d of %s in %s\n\n", len(result.ActionsCaches), text.Pluralize(result.TotalCount, "cache"), ghrepo.FullName(repo))
126 }
127
128 if opts.Now.IsZero() {
129 opts.Now = time.Now()
130 }
131
132 tp := tableprinter.New(opts.IO, tableprinter.WithHeader("ID", "KEY", "SIZE", "CREATED", "ACCESSED"))
133 for _, cache := range result.ActionsCaches {
134 tp.AddField(cs.Cyanf("%d", cache.Id))
135 tp.AddField(cache.Key)
136 tp.AddField(humanFileSize(cache.SizeInBytes))
137 tp.AddTimeField(opts.Now, cache.CreatedAt, cs.Muted)
138 tp.AddTimeField(opts.Now, cache.LastAccessedAt, cs.Muted)
139 tp.EndRow()
140 }
141
142 return tp.Render()
143}
144
145func humanFileSize(s int64) string {
146 if s < 1024 {

Callers 2

TestListRunFunction · 0.70
NewCmdListFunction · 0.70

Calls 15

NewClientFromHTTPFunction · 0.92
GetCachesFunction · 0.92
NewNoResultsErrorFunction · 0.92
FullNameFunction · 0.92
PluralizeFunction · 0.92
NewFunction · 0.92
WithHeaderFunction · 0.92
ColorSchemeMethod · 0.80
FailureIconMethod · 0.80
StartPagerMethod · 0.80
StopPagerMethod · 0.80
IsStdoutTTYMethod · 0.80

Tested by 1

TestListRunFunction · 0.56