mirror of
https://github.com/nix-community/comma.git
synced 2024-10-03 23:08:05 +03:00
Add an option to print the path instead of running it (#75)
* feat: add an option to print exe path * chore: fmt * style: add missing ;
This commit is contained in:
parent
1085a5af29
commit
efe30c16fc
@ -17,7 +17,7 @@ pub fn check_database_exists() -> Result<(), ()> {
|
||||
let database_file = get_database_file();
|
||||
if !database_file.exists() {
|
||||
eprintln!("Warning: Nix-index database does not exist, either obtain a prebuilt database from https://github.com/Mic92/nix-index-database or try updating with `nix run 'nixpkgs#nix-index' --extra-experimental-features 'nix-command flakes'`.");
|
||||
return Err(())
|
||||
return Err(());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
15
src/main.rs
15
src/main.rs
@ -142,6 +142,17 @@ fn main() -> ExitCode {
|
||||
} else if args.shell {
|
||||
let shell_cmd = shell::select_shell_from_pid(process::id()).unwrap_or("bash".into());
|
||||
run_command_or_open_shell(use_channel, &choice, &shell_cmd, &[], &args.nixpkgs_flake);
|
||||
} else if args.print_path {
|
||||
run_command_or_open_shell(
|
||||
use_channel,
|
||||
&choice,
|
||||
"sh",
|
||||
&[
|
||||
String::from("-c"),
|
||||
format!("printf '%s\n' \"$(realpath \"$(which {command})\")\""),
|
||||
],
|
||||
&args.nixpkgs_flake,
|
||||
);
|
||||
} else {
|
||||
run_command_or_open_shell(use_channel, &choice, command, trail, &args.nixpkgs_flake);
|
||||
}
|
||||
@ -180,6 +191,10 @@ struct Opt {
|
||||
#[clap(short = 'p', long = "print-package")]
|
||||
print_package: bool,
|
||||
|
||||
/// Print the absolute path to the executable in the nix store
|
||||
#[clap(short = 'x', long = "print-path")]
|
||||
print_path: bool,
|
||||
|
||||
/// Command to run
|
||||
#[clap(required_unless_present = "update", name = "cmd")]
|
||||
cmd: Vec<String>,
|
||||
|
Loading…
Reference in New Issue
Block a user