diff --git a/src/main.rs b/src/main.rs index 698930d..a150a0c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -117,10 +117,17 @@ fn run_command_or_open_shell( fn main() -> ExitCode { let args = Opt::parse(); - let mut cache = Cache::new(); - if let Err(ref e) = cache { - eprintln!("failed to initialize cache, disabling related functionality: {e}"); - } + let mut cache = if !args.ignore_cache { + match Cache::new() { + Err(e) => { + eprintln!("failed to initialize cache, disabling related functionality: {e}"); + None + } + Ok(x) => Some(x), + } + } else { + None + }; if args.update { eprintln!("\"comma --update\" has been deprecated. either obtain a prebuilt database from https://github.com/Mic92/nix-index-database or use \"nix run 'nixpkgs#nix-index' --extra-experimental-features 'nix-command flakes'\""); @@ -128,7 +135,7 @@ fn main() -> ExitCode { } if args.empty_cache { - if let Ok(ref mut cache) = cache { + if let Some(ref mut cache) = cache { cache.empty(); } } @@ -146,7 +153,7 @@ fn main() -> ExitCode { let trail = &args.cmd[1..]; if args.delete_entry { - if let Ok(ref mut cache) = cache { + if let Some(ref mut cache) = cache { cache.delete(command); } } @@ -170,13 +177,13 @@ fn main() -> ExitCode { } let derivation = match cache { - Ok(mut cache) => cache.query(command).or_else(|| { + Some(mut cache) => cache.query(command).or_else(|| { index_database_pick(command, &args.picker).map(|derivation| { cache.update(command, &derivation); derivation }) }), - Err(_) => index_database_pick(command, &args.picker), + None => index_database_pick(command, &args.picker), }; let derivation = match derivation { @@ -268,6 +275,10 @@ struct Opt { #[clap(short, long = "empty-cache")] empty_cache: bool, + /// Ignore the cache completely + #[clap(long = "ignore-cache", env = "COMMA_CACHING")] + ignore_cache: bool, + /// Overwrite the cache entry for the specified command. This is achieved by first deleting it /// from the cache, then running comma as normal. #[clap(short, long = "delete-entry")]