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

Function listRun

pkg/cmd/agent-task/list/list.go:63–157  ·  view source on GitHub ↗
(opts *ListOptions)

Source from the content-addressed store, hash-verified

61}
62
63func listRun(opts *ListOptions) error {
64 if opts.Web {
65 webURL := capi.AgentsHomeURL
66 if opts.IO.IsStdoutTTY() {
67 fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(webURL))
68 }
69 return opts.Browser.Browse(webURL)
70 }
71
72 if opts.Limit <= 0 {
73 opts.Limit = defaultLimit
74 }
75
76 capiClient, err := opts.CapiClient()
77 if err != nil {
78 return err
79 }
80
81 opts.IO.StartProgressIndicatorWithLabel("Fetching agent tasks...")
82 defer opts.IO.StopProgressIndicator()
83 var sessions []*capi.Session
84 ctx := context.Background()
85
86 sessions, err = capiClient.ListLatestSessionsForViewer(ctx, opts.Limit)
87 if err != nil {
88 return err
89 }
90
91 opts.IO.StopProgressIndicator()
92
93 if len(sessions) == 0 && opts.Exporter == nil {
94 return cmdutil.NewNoResultsError("no agent tasks found")
95 }
96
97 if opts.Exporter != nil {
98 return opts.Exporter.Write(opts.IO, sessions)
99 }
100
101 if err := opts.IO.StartPager(); err == nil {
102 defer opts.IO.StopPager()
103 } else {
104 fmt.Fprintf(opts.IO.ErrOut, "error starting pager: %v\n", err)
105 }
106
107 if opts.IO.IsStdoutTTY() {
108 count := len(sessions)
109 header := fmt.Sprintf("Showing %s", text.Pluralize(count, "session"))
110 fmt.Fprintf(opts.IO.Out, "%s\n\n", header)
111 }
112
113 cs := opts.IO.ColorScheme()
114 tp := tableprinter.New(opts.IO, tableprinter.WithHeader("Session Name", "Pull Request", "Repo", "Session State", "Created"))
115 for _, s := range sessions {
116 if s.ResourceType != "pull" || s.PullRequest == nil || s.PullRequest.Repository == nil {
117 // Skip these sessions in case they happen, for now.
118 continue
119 }
120

Callers 2

Test_listRunFunction · 0.70
NewCmdListFunction · 0.70

Calls 15

DisplayURLFunction · 0.92
NewNoResultsErrorFunction · 0.92
PluralizeFunction · 0.92
NewFunction · 0.92
WithHeaderFunction · 0.92
IsStdoutTTYMethod · 0.80
StartPagerMethod · 0.80
StopPagerMethod · 0.80
ColorSchemeMethod · 0.80
IsTTYMethod · 0.80
ColorFromStringMethod · 0.80
AddTimeFieldMethod · 0.80

Tested by 1

Test_listRunFunction · 0.56