| 110 | } |
| 111 | |
| 112 | func listRun(opts *ListOptions) error { |
| 113 | client, err := opts.HttpClient() |
| 114 | if err != nil { |
| 115 | return err |
| 116 | } |
| 117 | |
| 118 | cfg, err := opts.Config() |
| 119 | if err != nil { |
| 120 | return err |
| 121 | } |
| 122 | |
| 123 | host, _ := cfg.Authentication().DefaultHost() |
| 124 | |
| 125 | // Filtering can take a while so start the progress indicator. StopProgressIndicator will no-op if not running. |
| 126 | if opts.Filter != nil { |
| 127 | opts.IO.StartProgressIndicator() |
| 128 | } |
| 129 | gists, err := shared.ListGists(client, host, opts.Limit, opts.Filter, opts.IncludeContent, opts.Visibility) |
| 130 | opts.IO.StopProgressIndicator() |
| 131 | |
| 132 | if err != nil { |
| 133 | return err |
| 134 | } |
| 135 | |
| 136 | if len(gists) == 0 { |
| 137 | return cmdutil.NewNoResultsError("no gists found") |
| 138 | } |
| 139 | |
| 140 | if err := opts.IO.StartPager(); err == nil { |
| 141 | defer opts.IO.StopPager() |
| 142 | } else { |
| 143 | fmt.Fprintf(opts.IO.ErrOut, "failed to start pager: %v\n", err) |
| 144 | } |
| 145 | |
| 146 | if opts.Filter != nil && opts.IncludeContent { |
| 147 | return printContent(opts.IO, gists, opts.Filter) |
| 148 | } |
| 149 | |
| 150 | return printTable(opts.IO, gists, opts.Filter) |
| 151 | } |
| 152 | |
| 153 | func printTable(io *iostreams.IOStreams, gists []shared.Gist, filter *regexp.Regexp) error { |
| 154 | cs := io.ColorScheme() |