| 123 | } |
| 124 | |
| 125 | func commitsRun(opts *CommitsOptions) error { |
| 126 | io := opts.IO |
| 127 | if opts.WebMode { |
| 128 | url := opts.Searcher.URL(opts.Query) |
| 129 | if io.IsStdoutTTY() { |
| 130 | fmt.Fprintf(io.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(url)) |
| 131 | } |
| 132 | return opts.Browser.Browse(url) |
| 133 | } |
| 134 | io.StartProgressIndicator() |
| 135 | result, err := opts.Searcher.Commits(opts.Query) |
| 136 | io.StopProgressIndicator() |
| 137 | if err != nil { |
| 138 | return err |
| 139 | } |
| 140 | if len(result.Items) == 0 && opts.Exporter == nil { |
| 141 | return cmdutil.NewNoResultsError("no commits matched your search") |
| 142 | } |
| 143 | if err := io.StartPager(); err == nil { |
| 144 | defer io.StopPager() |
| 145 | } else { |
| 146 | fmt.Fprintf(io.ErrOut, "failed to start pager: %v\n", err) |
| 147 | } |
| 148 | if opts.Exporter != nil { |
| 149 | return opts.Exporter.Write(io, result.Items) |
| 150 | } |
| 151 | |
| 152 | return displayResults(io, opts.Now, result) |
| 153 | } |
| 154 | |
| 155 | func displayResults(io *iostreams.IOStreams, now time.Time, results search.CommitsResult) error { |
| 156 | if now.IsZero() { |