| 95 | } |
| 96 | |
| 97 | func viewRun(opts *ViewOptions) error { |
| 98 | findOptions := shared.FindOptions{ |
| 99 | Selector: opts.SelectorArg, |
| 100 | Fields: defaultFields, |
| 101 | Detector: opts.Detector, |
| 102 | } |
| 103 | if opts.BrowserMode { |
| 104 | findOptions.Fields = []string{"url"} |
| 105 | } else if opts.Exporter != nil { |
| 106 | findOptions.Fields = opts.Exporter.Fields() |
| 107 | } |
| 108 | pr, baseRepo, err := opts.Finder.Find(findOptions) |
| 109 | if err != nil { |
| 110 | return err |
| 111 | } |
| 112 | |
| 113 | connectedToTerminal := opts.IO.IsStdoutTTY() |
| 114 | |
| 115 | if opts.BrowserMode { |
| 116 | openURL := pr.URL |
| 117 | if connectedToTerminal { |
| 118 | fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(openURL)) |
| 119 | } |
| 120 | return opts.Browser.Browse(openURL) |
| 121 | } |
| 122 | |
| 123 | opts.IO.DetectTerminalTheme() |
| 124 | if err := opts.IO.StartPager(); err == nil { |
| 125 | defer opts.IO.StopPager() |
| 126 | } else { |
| 127 | fmt.Fprintf(opts.IO.ErrOut, "failed to start pager: %v\n", err) |
| 128 | } |
| 129 | |
| 130 | if opts.Exporter != nil { |
| 131 | return opts.Exporter.Write(opts.IO, pr) |
| 132 | } |
| 133 | |
| 134 | if connectedToTerminal { |
| 135 | return printHumanPrPreview(opts, baseRepo, pr) |
| 136 | } |
| 137 | |
| 138 | if opts.Comments { |
| 139 | fmt.Fprint(opts.IO.Out, shared.RawCommentList(pr.Comments, pr.DisplayableReviews())) |
| 140 | return nil |
| 141 | } |
| 142 | |
| 143 | return printRawPrPreview(opts.IO, pr) |
| 144 | } |
| 145 | |
| 146 | func printRawPrPreview(io *iostreams.IOStreams, pr *api.PullRequest) error { |
| 147 | out := io.Out |