Skip to content

fix: skip version check for generator commands#9064

Merged
olblak merged 5 commits into
updatecli:mainfrom
ambikeesshh:fix/version-banner-stderr
Jun 2, 2026
Merged

fix: skip version check for generator commands#9064
olblak merged 5 commits into
updatecli:mainfrom
ambikeesshh:fix/version-banner-stderr

Conversation

@ambikeesshh

@ambikeesshh ambikeesshh commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Fix #9028

Summary

The version check in PersistentPostRun runs for every subcommand, including completion. Since logrus output goes to stdout, the "new release available" banner gets captured into generated shell completion scripts, producing an invalid file that breaks the user shell on startup.

This hits Homebrew users especially hard since completions are generated at install time, so every new shell gets a syntax error.

What changed

  • Added --disable-version-check flag and UPDATECLI_DISABLE_VERSION_CHECK env var (same pattern as --disable-changelog)
  • Skip version check for generator commands: completion, __complete, __completeNoDesc, docs, man, jsonschema
  • Walk up the command tree with cmd.Parent() so nested subcommands like completion bash are also correctly skipped
  • Added tests for flag registration, env var defaults, flag override, and skip list contents

Test

go test ./cmd/...
go build -o /tmp/updatecli . && /tmp/updatecli completion bash > test.bash && bash -n test.bash

Note: bash -n only catches the issue if a newer version of updatecli is available (which is what triggers the banner). If you are already on the latest version, no banner is emitted so the test passes regardless.

Additional Information

Checklist

  • I have updated the documentation via pull request in website repository.

Tradeoff

  • The version check is skipped entirely for generator commands rather than routing the banner to stderr. This avoids the corruption but means users will not see version notifications when running these commands.
  • New generator commands added in the future need to be added to the skip list.
  • The root cause (logrus.SetOutput(os.Stdout) sending diagnostic output to stdout) is not addressed here. A follow-up could route the banner to stderr as a more general fix.

@ambikeesshh

Copy link
Copy Markdown
Contributor Author

@olblak, PTAL

This PR fixes the immediate problem (banner corrupting completion scripts) by skipping the version check for generator commands and adding the --disable-version-check flag. But the root cause from #9028 is still open: logrus.SetOutput(os.Stdout) means the banner goes to stdout, so any command where someone pipes stdout could still get the banner mixed into their output

The issue suggested routing the banner to stderr as one of the fixes. I held off on that here to keep the scope small, but happy to include it in this PR if you'd prefer. Otherwise I can open a follow-up.

thanks!!

@olblak

olblak commented Jun 2, 2026

Copy link
Copy Markdown
Member

Thanks for the pullrequest, I like the environment variable and flag to totally disable the version checking as it can reduce http queries to updatecli.io

I am struggling to test this change manually or other changes.

I am curious what you think about my suggestion on #9028 (comment).
The idea would to only run the check version in a defer function so in theory it wouldn't be executed on auto completation.

Regarding moving the message to stderr, I don't know if it's the time to do it as I would like to revamp to UI and move away from logrus completely, but I never took the time

@ambikeesshh

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback @olblak!

Regarding the defer approach in run() - I think that's cleaner than the skip list. The skip list works but every new generator command needs to be manually added. With defer inside run(), the version check naturally only runs for commands that go through that function, so completion/docs/man/etc. are excluded without any extra logic.

The tradeoff is that some commands in run() like udash/login, udash/logout, manifest/pull probably don't need the version check either, but since they don't redirect stdout it's not harmful, just an extra network request. The skip list is more surgical, but defer is simpler and harder to get wrong.

I'd lean toward defer for simplicity, and keep the --disable-version-check flag either way so users can opt out regardless of which command they're running. That also helps with reducing HTTP queries to updatecli.io.

As for only checking on updatecli version - that feels a bit too restrictive since most users don't run that directly, so they'd never see the update notification. The current approach surfaces it during normal usage which is more useful.

Happy to refactor to the defer approach if that's your preference. And understood on stderr/logrus, makes sense to handle that as part of a larger UI revamp.

@olblak

olblak commented Jun 2, 2026

Copy link
Copy Markdown
Member

I could manually test it running

go build -ldflags="-X github.com/updatecli/updatecli/pkg/core/version.Version=v0.1.0" -o bin/updatecli .
./bin/updatecli completion bash > /tmp/completions.bash
grep -n 'new release' /tmp/completions.bash
bash -norc /tmp/completions.bash

Where we shouldn't see 427:| A new release is available: "0.1.0" -> "0.117.1"

@olblak

olblak commented Jun 2, 2026

Copy link
Copy Markdown
Member

After additional testing, your approach is better, as not every subcommand calls the run function
So, for example, my suggestion wouldn't work with updatecli version

olblak added 2 commits June 2, 2026 09:25
Signed-off-by: Olblak <me@olblak.com>
@ambikeesshh

Copy link
Copy Markdown
Contributor Author

Good catch on updatecli version @olblak, that would have been an ironic miss. Thanks for fixing the formatting too. Skip list it is, I'll keep an eye on CI.

@ambikeesshh

Copy link
Copy Markdown
Contributor Author

looks like the analyse check hit a gitHub rate limit. mind re-running it when you get a chance @olblak?
thanks!

@ambikeesshh

Copy link
Copy Markdown
Contributor Author

all checks passed @olblak. ready for merge whenever you are :)

@olblak

olblak commented Jun 2, 2026

Copy link
Copy Markdown
Member

Thank you for the pullrequest today I learn

@olblak olblak merged commit bdd799e into updatecli:main Jun 2, 2026
7 of 11 checks passed
@olblak olblak added bug Something isn't working core All things related to Updatecli core engine labels Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working core All things related to Updatecli core engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Version-check banner is written to stdout in PersistentPostRun, corrupting generated shell completions

2 participants