Skip to content

Commit

Permalink
fixed build file for latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
qxrein committed Oct 18, 2024
1 parent e3e8617 commit 6bff39b
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use std::fs;

use clap_complete::{generate_to, Shell};
use std::path::PathBuf;
use std::error::Error;
use clap_complete::{generate_to, shells::Shell};

include!("src/cli.rs");

fn main() {
let var = std::env::var_os("SHELL_COMPLETIONS_DIR").or_else(|| std::env::var_os("OUT_DIR"));
let outdir = match var {
None => return,
Some(outdir) => outdir,
};
fs::create_dir_all(&outdir).unwrap();
fn main() -> Result<(), Box<dyn Error>> {
let outdir = get_output_dir()?;
fs::create_dir_all(&outdir)?;

let mut command = build_command();
for shell in [
Expand All @@ -20,6 +17,17 @@ fn main() {
Shell::PowerShell,
Shell::Elvish,
] {
generate_to(shell, &mut command, "hyperfine", &outdir).unwrap();
generate_to(shell, &mut command, "hyperfine", &outdir)
.map_err(|e| format!("Failed to generate completions for {:?}: {}", shell, e))?;
}

println!("Completions generated successfully in {:?}", outdir);
Ok(())
}

fn get_output_dir() -> Result<PathBuf, Box<dyn Error>> {
std::env::var_os("SHELL_COMPLETIONS_DIR")
.or_else(|| std::env::var_os("OUT_DIR"))
.map(PathBuf::from)
.ok_or_else(|| "Neither SHELL_COMPLETIONS_DIR nor OUT_DIR environment variable is set".into())
}

0 comments on commit 6bff39b

Please sign in to comment.