| 82 | } |
| 83 | |
| 84 | func 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 | |
| 135 | func printLabels(io *iostreams.IOStreams, labels []label) error { |
| 136 | cs := io.ColorScheme() |