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

Function listRun

pkg/cmd/label/list.go:84–133  ·  view source on GitHub ↗
(opts *listOptions)

Source from the content-addressed store, hash-verified

82}
83
84func listRun(opts *listOptions) error {
85 httpClient, err := opts.HttpClient()
86 if err != nil {
87 return err
88 }
89
90 baseRepo, err := opts.BaseRepo()
91 if err != nil {
92 return err
93 }
94
95 if opts.WebMode {
96 labelListURL := ghrepo.GenerateRepoURL(baseRepo, "labels")
97
98 if opts.IO.IsStdoutTTY() {
99 fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(labelListURL))
100 }
101
102 return opts.Browser.Browse(labelListURL)
103 }
104
105 if opts.Exporter != nil {
106 opts.Query.fields = opts.Exporter.Fields()
107 }
108
109 opts.IO.StartProgressIndicator()
110 labels, totalCount, err := listLabels(httpClient, baseRepo, opts.Query)
111 opts.IO.StopProgressIndicator()
112 if err != nil {
113 return err
114 }
115
116 if len(labels) == 0 {
117 if opts.Query.Query != "" {
118 return cmdutil.NewNoResultsError(fmt.Sprintf("no labels in %s matched your search", ghrepo.FullName(baseRepo)))
119 }
120 return cmdutil.NewNoResultsError(fmt.Sprintf("no labels found in %s", ghrepo.FullName(baseRepo)))
121 }
122
123 if opts.Exporter != nil {
124 return opts.Exporter.Write(opts.IO, labels)
125 }
126
127 if opts.IO.IsStdoutTTY() {
128 title := listHeader(ghrepo.FullName(baseRepo), len(labels), totalCount)
129 fmt.Fprintf(opts.IO.Out, "\n%s\n\n", title)
130 }
131
132 return printLabels(opts.IO, labels)
133}
134
135func printLabels(io *iostreams.IOStreams, labels []label) error {
136 cs := io.ColorScheme()

Callers 2

TestListRunFunction · 0.70
newCmdListFunction · 0.70

Calls 14

GenerateRepoURLFunction · 0.92
DisplayURLFunction · 0.92
NewNoResultsErrorFunction · 0.92
FullNameFunction · 0.92
listLabelsFunction · 0.85
printLabelsFunction · 0.85
IsStdoutTTYMethod · 0.80
listHeaderFunction · 0.70
BaseRepoMethod · 0.65
BrowseMethod · 0.65
FieldsMethod · 0.65

Tested by 1

TestListRunFunction · 0.56