@@ -58,11 +58,9 @@ func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Comman
5858 // support `-R, --repo` override
5959 opts .BaseRepo = f .BaseRepo
6060
61- terminal := opts .IO .IsStdoutTTY () && opts .IO .IsStdinTTY ()
62-
6361 if len (args ) > 0 {
6462 opts .JobID = args [0 ]
65- } else if ! terminal {
63+ } else if ! opts . IO . CanPrompt () {
6664 return & cmdutil.FlagError {Err : errors .New ("job ID required when not running interactively" )}
6765 } else {
6866 opts .Prompt = true
@@ -76,7 +74,7 @@ func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Comman
7674 }
7775 cmd .Flags ().BoolVarP (& opts .Log , "log" , "l" , false , "Print full logs for job" )
7876 // TODO should we try and expose pending via another exit code?
79- cmd .Flags ().BoolVarP (& opts .ExitStatus , "exit-status" , "e " , false , "Exit with non-zero status if job failed" )
77+ cmd .Flags ().BoolVar (& opts .ExitStatus , "exit-status" , false , "Exit with non-zero status if job failed" )
8078
8179 return cmd
8280}
@@ -107,14 +105,14 @@ func runView(opts *ViewOptions) error {
107105 fmt .Fprintln (out )
108106
109107 opts .IO .StartProgressIndicator ()
108+ defer opts .IO .StopProgressIndicator ()
110109
111110 run , err := shared .GetRun (client , repo , runID )
112111 if err != nil {
113112 return fmt .Errorf ("failed to get run: %w" , err )
114113 }
115114
116115 opts .IO .StopProgressIndicator ()
117-
118116 jobID , err = promptForJob (* opts , client , repo , * run )
119117 if err != nil {
120118 return err
@@ -124,21 +122,16 @@ func runView(opts *ViewOptions) error {
124122 }
125123
126124 opts .IO .StartProgressIndicator ()
127-
128125 job , err := getJob (client , repo , jobID )
129126 if err != nil {
130127 return fmt .Errorf ("failed to get job: %w" , err )
131128 }
132129
133- opts .IO .StopProgressIndicator ()
134-
135130 if opts .Log {
136- opts .IO .StartProgressIndicator ()
137131 r , err := client .JobLog (repo , jobID )
138132 if err != nil {
139133 return err
140134 }
141- opts .IO .StopProgressIndicator ()
142135
143136 if _ , err := io .Copy (out , r ); err != nil {
144137 return fmt .Errorf ("failed to read log: %w" , err )
@@ -152,29 +145,31 @@ func runView(opts *ViewOptions) error {
152145 }
153146
154147 annotations , err := shared .GetAnnotations (client , repo , * job )
148+ opts .IO .StopProgressIndicator ()
155149 if err != nil {
156150 return fmt .Errorf ("failed to get annotations: %w" , err )
157151 }
158152
159- opts .IO .StopProgressIndicator ()
160-
161153 elapsed := job .CompletedAt .Sub (job .StartedAt )
162154 elapsedStr := fmt .Sprintf (" in %s" , elapsed )
163155 if elapsed < 0 {
164156 elapsedStr = ""
165157 }
166158
159+ symbol , symColor := shared .Symbol (cs , job .Status , job .Conclusion )
160+
167161 fmt .Fprintf (out , "%s (ID %s)\n " , cs .Bold (job .Name ), cs .Cyanf ("%d" , job .ID ))
168162 fmt .Fprintf (out , "%s %s ago%s\n " ,
169- shared . Symbol ( cs , job . Status , job . Conclusion ),
163+ symColor ( symbol ),
170164 utils .FuzzyAgoAbbr (opts .Now (), job .StartedAt ),
171165 elapsedStr )
172166
173167 fmt .Fprintln (out )
174168
175169 for _ , step := range job .Steps {
170+ stepSym , stepSymColor := shared .Symbol (cs , step .Status , step .Conclusion )
176171 fmt .Fprintf (out , "%s %s\n " ,
177- shared . Symbol ( cs , step . Status , step . Conclusion ),
172+ stepSymColor ( stepSym ),
178173 step .Name )
179174 }
180175
@@ -227,8 +222,8 @@ func promptForJob(opts ViewOptions, client *api.Client, repo ghrepo.Interface, r
227222 candidates := []string {}
228223
229224 for _ , job := range jobs {
230- symbol := shared .Symbol (cs , job .Status , job .Conclusion )
231- candidates = append (candidates , fmt .Sprintf ("%s %s" , symbol , job .Name ))
225+ symbol , symColor := shared .Symbol (cs , job .Status , job .Conclusion )
226+ candidates = append (candidates , fmt .Sprintf ("%s %s" , symColor ( symbol ) , job .Name ))
232227 }
233228
234229 // TODO consider custom filter so it's fuzzier. right now matches start anywhere in string but
0 commit comments