Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optionally disable caching #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,25 @@ 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'\"");
index::update_database();
}

if args.empty_cache {
if let Ok(ref mut cache) = cache {
if let Some(ref mut cache) = cache {
cache.empty();
}
}
Expand All @@ -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);
}
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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")]
Expand Down