Silence the missing-cache message under --quiet (#500)

This commit is contained in:
VXNCXNX 2026-08-16 23:25:00 +02:00 committed by GitHub
commit 64db5accfa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 14 deletions

View file

@ -349,20 +349,22 @@ fn try_main(args: Cli, enable_styles: bool) -> Result<ExitCode> {
} else if args.list || !command.is_empty() {
// Cache is needed for these commands to work
let Some(cache) = Cache::open(cache_config)? else {
print_error(
enable_styles,
&anyhow::anyhow!(
"Page cache not found. Please run `tldr --update` to download the cache."
),
);
println!("\nNote: You can optionally enable automatic cache updates by adding the");
println!("following config to your config file:\n");
println!(" [updates]");
println!(" auto_update = true\n");
println!("The path to your config file can be looked up with `tldr --show-paths`.");
println!("To create an initial config file, use `tldr --seed-config`.\n");
println!("You can find more tips and tricks in our docs:\n");
println!(" https://tealdeer-rs.github.io/tealdeer/config_updates.html");
if !args.quiet {
print_error(
enable_styles,
&anyhow::anyhow!(
"Page cache not found. Please run `tldr --update` to download the cache."
),
);
println!("\nNote: You can optionally enable automatic cache updates by adding the");
println!("following config to your config file:\n");
println!(" [updates]");
println!(" auto_update = true\n");
println!("The path to your config file can be looked up with `tldr --show-paths`.");
println!("To create an initial config file, use `tldr --seed-config`.\n");
println!("You can find more tips and tricks in our docs:\n");
println!(" https://tealdeer-rs.github.io/tealdeer/config_updates.html");
}
return Ok(ExitCode::FAILURE);
};

View file

@ -468,6 +468,21 @@ fn test_quiet_failures() {
.stdout(is_empty());
}
#[test]
fn test_quiet_missing_cache() {
let testenv = TestEnv::new();
for args in [["--list", "--quiet"], ["sl", "--quiet"]] {
testenv
.command()
.args(args)
.assert()
.failure()
.stdout(is_empty())
.stderr(is_empty());
}
}
#[test]
fn test_quiet_old_cache() {
let testenv = TestEnv::new().install_default_cache();