Show error and exit upon nix-locate failure

Co-authored-by: gabriel-doriath-dohler <gabriel.doriath.dohler@ens.fr>
This commit is contained in:
Artturin 2022-11-20 17:57:03 +02:00
parent 4ed30d58db
commit 1fbd317b4a

View File

@ -72,12 +72,21 @@ fn main() -> ExitCode {
index::check_database();
let attrs = Command::new("nix-locate")
let nix_locate_output = Command::new("nix-locate")
.args(["--top-level", "--minimal", "--at-root", "--whole-name"])
.arg(format!("/bin/{}", command))
.output()
.expect("failed to execute nix-locate")
.stdout;
.expect("failed to execute nix-locate");
if !nix_locate_output.status.success() {
match std::str::from_utf8(&nix_locate_output.stderr) {
Ok(stderr) => eprintln!("nix-locate failed with: {}", stderr),
Err(_) => eprint!("nix-locate failed"),
}
return ExitCode::FAILURE;
}
let attrs = nix_locate_output.stdout;
if attrs.is_empty() {
eprintln!("No executable `{}` found in nix-index database.", command);