Repository navigation
fix: don't check for updates in completion subcommand - #609
Conversation
SergioGasquez
left a comment
There was a problem hiding this comment.
Thanks for the PR! The change works as described: with --skip-update, espup completions zsh goes from ~560 ms to ~9 ms locally, stdout stays clean, and fmt/clippy/tests pass. A few recommendations inline, the main ones being the env var parsing and whether we need a flag at all.
| if !args.skip_update { | ||
| check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")); | ||
| } |
There was a problem hiding this comment.
Should completions check for updates at all? It's a non-interactive command whose output gets sourced, and the check is never cached (Duration::ZERO) and uses update-informer's default 5 s timeout, so on a slow/offline network every shell startup can stall for up to 5 s.
Just removing the check_for_update call here would fix #608 for everyone, without the new flag, env var, README and CHANGELOG changes.
There was a problem hiding this comment.
You're right. I was worried about backward compatibility, but it doesn't seem to be a real issue here.
I'll just remove the check_for_update call. Thank you for the great review!
| #[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])] | ||
| pub log_level: String, | ||
| /// Skips checking crates.io for a newer version of espup. | ||
| #[arg(long, env = "ESPUP_SKIP_UPDATE")] |
There was a problem hiding this comment.
With a plain bool + env, clap only accepts true/false:
ESPUP_SKIP_UPDATE=1/yes->error: invalid value '1' for '--skip-update'ESPUP_SKIP_UPDATE=->error: a value is required
For the eval "$(espup completions zsh)" use case this produces empty stdout, so completions silently stop working. Since this env var is meant to be exported in rc files, consider:
#[arg(long, env = "ESPUP_SKIP_UPDATE", value_parser = clap::builder::BoolishValueParser::new())]Also, naming/scope: --skip-update reads like skipping the espup update subcommand; --no-update-check would be clearer. And ESPUP_SKIP_UPDATE sounds global but only completions honors it, while install/update/uninstall still check. Either scope the name or apply it to all subcommands.
There was a problem hiding this comment.
Since I'm removing the check_for_update call (src/main.rs:42-44), the --skip-update flag and the ESPUP_SKIP_UPDATE env var are no longer needed, so I'll remove them.
| #[test] | ||
| fn completions_with_skip_update() { | ||
| assert_cmd::Command::new(assert_cmd::cargo_bin!("espup")) | ||
| .args(["completions", "--skip-update", "bash"]) | ||
| .assert() | ||
| .success(); | ||
| } |
There was a problem hiding this comment.
This also passes without the flag, since update-check failures are ignored (.ok().flatten()), so it doesn't verify the check is skipped. Parse tests in src/cli.rs similar to install_accepts_disable_timeouts_flag/_env_var would cover the flag and env var (including "1" if the parser changes).
There was a problem hiding this comment.
This test will be removed too, since the flag no longer exists.
| ## [Unreleased] | ||
|
|
||
| ### Added | ||
| - Added `--skip-update` (`ESPUP_SKIP_UPDATE`) to the `completions` subcommand to skip the crates.io version check |
There was a problem hiding this comment.
Nit: other entries include the PR number, e.g. ... version check (#609).
There was a problem hiding this comment.
Thank, I'll add the PR number.
a508970 to
310687d
Compare
--skip-update flag to completions subcommandcompletion subcommand
310687d to
a6f454e
Compare
|
@SergioGasquez Thank you for your review. I have removed |
espup completionsalways queried crates.io for update before generating completion script.Add
--skip-update(or setESPUP_SKIP_UPDATE) to skip this check. The default behavior is not changed.Issue
See #608