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