@@ -246,15 +246,12 @@ func newRootCmd(v string) *cobra.Command {
246246func Execute () {
247247 root := newRootCmd (version )
248248
249- // Pre-flight skip: the opt-out env var, CI, stderr TTY-ness, and the build
250- // version are all known before the command parses its flags, so when any
251- // of them opts out we never launch the network call at all. (JSONMode and
252- // Quiet come from flags parsed during Execute, so they can't be evaluated
253- // here — they're handled by the post-command notice gate below, which may
254- // still suppress a notice whose cache refresh we deliberately allowed.)
249+ // Skip the network call entirely for opt-outs knowable before flags parse.
250+ // Uses IsTerminal, not IsTTY, so NO_COLOR (a styling pref) still gets checks.
251+ // JSONMode/Quiet are flag-derived and gate only the notice, below.
255252 preSkip := updater .ShouldSkip (updater.Conditions {
256253 CurrentVersion : version ,
257- StderrTTY : ui .IsTTY (root .ErrOrStderr ()),
254+ StderrTTY : ui .IsTerminal (root .ErrOrStderr ()),
258255 OptOut : env .UpdateNotifierOptOut (),
259256 })
260257
@@ -264,28 +261,24 @@ func Execute() {
264261 defer updCancel ()
265262 resultCh := make (chan updater.Result , 1 )
266263 if preSkip == updater .SkipNone {
264+ // Run even when we may end up skipping the notice (e.g. JSON mode) so
265+ // the cache still refreshes; the gate below decides on printing.
267266 go func () {
268- // Conservatively run the network call even when we might end up
269- // skipping the *notice* (e.g. JSON mode), so the cache refresh
270- // still happens. The notice gate below makes the final call.
271267 resultCh <- updater .Check (updCtx , version , updater .CacheDir ())
272268 }()
273269 }
274270
275271 runErr := root .Execute ()
276272
277- // Decide whether the *notice* should be considered for printing. This
278- // is the gate the user perceives — silent skips don't even touch the
279- // channel below, so a hung check doesn't delay exit in those cases. When
280- // the pre-flight already opted out, no goroutine is running, so we keep
281- // that reason and never wait on the channel.
273+ // Re-check with the now-parsed flags to gate the notice. If the pre-flight
274+ // already opted out, no goroutine ran, so keep that reason.
282275 skip := preSkip
283276 if skip == updater .SkipNone {
284277 skip = updater .ShouldSkip (updater.Conditions {
285278 CurrentVersion : version ,
286279 JSONMode : jsonOutput ,
287280 Quiet : quietMode ,
288- StderrTTY : ui .IsTTY (root .ErrOrStderr ()),
281+ StderrTTY : ui .IsTerminal (root .ErrOrStderr ()),
289282 OptOut : env .UpdateNotifierOptOut (),
290283 })
291284 }
0 commit comments