Skip to content

Commit 2c6fca8

Browse files
authored
Merge pull request #112 from ClickHouse/issue-111-update-notice-help-only
Only show update notice on --help output
2 parents 341bbd6 + 0edf57d commit 2c6fca8

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

src/main.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,30 @@ use cli::{
1515
CloudCommands, Commands, InvitationCommands, KeyCommands, MemberCommands, OrgCommands,
1616
PrivateEndpointCommands, QueryEndpointCommands, ServiceCommands, SkillsArgs, UpdateArgs,
1717
};
18+
use clap::error::ErrorKind;
1819

1920
use cloud::CloudClient;
2021
use error::{Error, Result};
2122

2223
#[tokio::main]
2324
async fn main() {
24-
let cli = Cli::parse();
25+
let cli = match Cli::try_parse() {
26+
Ok(cli) => cli,
27+
Err(e) => {
28+
// For --help and --version, show the update notice after the output
29+
if e.kind() == ErrorKind::DisplayHelp || e.kind() == ErrorKind::DisplayVersion {
30+
e.print().expect("failed to print output");
31+
update::print_cached_update_notice();
32+
std::process::exit(0);
33+
}
34+
e.exit();
35+
}
36+
};
2537

26-
// For non-update commands: print a cached update notice (sync, no network)
27-
// and spawn a background task to refresh the cache.
38+
// Spawn a background task to refresh the update cache for non-update commands.
39+
// The notice itself is only shown on --help (above), not during normal execution.
2840
let is_update_cmd = matches!(cli.command, Commands::Update(_));
2941
let cache_refresh = if !is_update_cmd {
30-
update::print_cached_update_notice();
3142
Some(tokio::spawn(update::refresh_update_cache()))
3243
} else {
3344
None

0 commit comments

Comments
 (0)