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

Function listRun

pkg/cmd/event/subscription/list/list.go:68–115  ·  view source on GitHub ↗
(ctx context.Context, opts *ListOptions)

Source from the content-addressed store, hash-verified

66}
67
68func listRun(ctx context.Context, opts *ListOptions) error {
69 cfg, err := opts.Config()
70 if err != nil {
71 return err
72 }
73 host, _ := cfg.Authentication().DefaultHost()
74
75 c, err := opts.EventClient(host)
76 if err != nil {
77 return err
78 }
79
80 opts.IO.StartProgressIndicator()
81 subs, err := c.ListSubscriptions(ctx, opts.Limit)
82 opts.IO.StopProgressIndicator()
83 if err != nil {
84 return fmt.Errorf("failed to list subscriptions: %w", err)
85 }
86
87 if opts.Exporter != nil {
88 return opts.Exporter.Write(opts.IO, subs)
89 }
90
91 if len(subs) == 0 {
92 return cmdutil.NewNoResultsError("no event subscriptions")
93 }
94
95 isTTY := opts.IO.IsStdoutTTY()
96 if isTTY {
97 fmt.Fprintf(opts.IO.Out, "\n%s\n\n", listHeader(len(subs), opts.Limit))
98 }
99 cs := opts.IO.ColorScheme()
100 now := opts.Now()
101 tp := tableprinter.New(opts.IO, tableprinter.WithHeader("ID", "RESOURCE", "EVENTS", "EXPIRES"))
102 for _, sub := range subs {
103 tp.AddField(sub.ID, tableprinter.WithColor(cs.Cyan))
104 tp.AddField(sub.ResourceURL)
105 if isTTY {
106 tp.AddField(strings.Join(sub.EventTypes, ", "))
107 tp.AddField(text.FuzzyIn(now, sub.ExpiresAt), tableprinter.WithColor(cs.Muted))
108 } else {
109 tp.AddField(strings.Join(sub.EventTypes, ","))
110 tp.AddField(sub.ExpiresAt.Format(time.RFC3339))
111 }
112 tp.EndRow()
113 }
114 return tp.Render()
115}
116
117// listHeader describes the listed subscriptions. The API reports no total, so a full page may not be all of them.
118func listHeader(count, limit int) string {

Callers 3

TestListRunFunction · 0.70
TestListRunDefaultHostFunction · 0.70
NewCmdListFunction · 0.70

Calls 15

NewNoResultsErrorFunction · 0.92
NewFunction · 0.92
WithHeaderFunction · 0.92
FuzzyInFunction · 0.92
IsStdoutTTYMethod · 0.80
ColorSchemeMethod · 0.80
JoinMethod · 0.80
listHeaderFunction · 0.70
ConfigMethod · 0.65
DefaultHostMethod · 0.65
AuthenticationMethod · 0.65

Tested by 2

TestListRunFunction · 0.56
TestListRunDefaultHostFunction · 0.56