MCPcopy Index your code
hub / github.com/cli/cli / listRun

Function listRun

pkg/cmd/workflow/list/list.go:69–124  ·  view source on GitHub ↗
(opts *ListOptions)

Source from the content-addressed store, hash-verified

67}
68
69func listRun(opts *ListOptions) error {
70 repo, err := opts.BaseRepo()
71 if err != nil {
72 return err
73 }
74
75 httpClient, err := opts.HttpClient()
76 if err != nil {
77 return fmt.Errorf("could not create http client: %w", err)
78 }
79 client := api.NewClientFromHTTP(httpClient)
80
81 opts.IO.StartProgressIndicator()
82 workflows, err := shared.GetWorkflows(client, repo, opts.Limit)
83 opts.IO.StopProgressIndicator()
84 if err != nil {
85 return fmt.Errorf("could not get workflows: %w", err)
86 }
87
88 var filteredWorkflows []shared.Workflow
89 if opts.All {
90 filteredWorkflows = workflows
91 } else {
92 for _, workflow := range workflows {
93 if !workflow.Disabled() {
94 filteredWorkflows = append(filteredWorkflows, workflow)
95 }
96 }
97 }
98
99 if len(filteredWorkflows) == 0 {
100 return cmdutil.NewNoResultsError("no workflows found")
101 }
102
103 if err := opts.IO.StartPager(); err == nil {
104 defer opts.IO.StopPager()
105 } else {
106 fmt.Fprintf(opts.IO.ErrOut, "failed to start pager: %v\n", err)
107 }
108
109 if opts.Exporter != nil {
110 return opts.Exporter.Write(opts.IO, filteredWorkflows)
111 }
112
113 cs := opts.IO.ColorScheme()
114 tp := tableprinter.New(opts.IO, tableprinter.WithHeader("Name", "State", "ID"))
115
116 for _, workflow := range filteredWorkflows {
117 tp.AddField(workflow.Name)
118 tp.AddField(string(workflow.State))
119 tp.AddField(fmt.Sprintf("%d", workflow.ID), tableprinter.WithColor(cs.Cyan))
120 tp.EndRow()
121 }
122
123 return tp.Render()
124}

Callers 2

TestListRunFunction · 0.70
NewCmdListFunction · 0.70

Calls 15

NewClientFromHTTPFunction · 0.92
GetWorkflowsFunction · 0.92
NewNoResultsErrorFunction · 0.92
NewFunction · 0.92
WithHeaderFunction · 0.92
DisabledMethod · 0.80
StartPagerMethod · 0.80
StopPagerMethod · 0.80
ColorSchemeMethod · 0.80
BaseRepoMethod · 0.65
ErrorfMethod · 0.65

Tested by 1

TestListRunFunction · 0.56