Skip to content

Commit

Permalink
Update shell completions destination
Browse files Browse the repository at this point in the history
  • Loading branch information
liamdawson committed Mar 14, 2024
1 parent c6e73d5 commit a6e9ceb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/ref/
/completions/
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-
pr-run-mode = "plan"

include = [
"target/release/_buildkite_waiter",
"target/release/_buildkite_waiter.ps1",
"target/release/buildkite_waiter.bash",
"target/release/buildkite_waiter.elv",
"target/release/buildkite_waiter.fish",
"target/release/buildkite_waiter.ts",
"completions/_buildkite_waiter",
"completions/_buildkite_waiter.ps1",
"completions/buildkite_waiter.bash",
"completions/buildkite_waiter.elv",
"completions/buildkite_waiter.fish",
"completions/buildkite_waiter.ts",
]

[workspace.metadata.dist.dependencies.apt]
Expand Down
40 changes: 19 additions & 21 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,25 @@ use clap::CommandFactory;
use clap_complete::Shell;
use cli::Cli;
use std::ffi::OsStr;
use std::fs::File;
use std::{env, path::PathBuf};

fn main() {
let target_dir = match env::var_os("OUT_DIR") {
// if no OUT_DIR, no need to write man/completions
None => return,
Some(outdir) => PathBuf::from(outdir),
};

let mut completion_dirs = vec![target_dir.clone()];
if env::var("PROFILE") != Ok("release".to_string()) {
// only generate completions on release builds
return;
}

if Ok("release".to_string()) == env::var("PROFILE") {
if let Some(manifest_dir) = env::var_os("CARGO_MANIFEST_DIR") {
completion_dirs.push(PathBuf::from(manifest_dir).join("target").join("release"));
}
let target_dir = match env::var_os("CARGO_MANIFEST_DIR") {
// if no CARGO_MANIFEST_DIR, don't completions
None => return,
Some(outdir) => PathBuf::from(outdir).join("completions"),
};

dbg!(&completion_dirs);

for target_dir in completion_dirs {
generate_completions(target_dir.as_os_str());
if !target_dir.exists() {
std::fs::create_dir_all(&target_dir).expect("should find or create completions directory");
}

let anchor = PathBuf::from(&target_dir).join("buildkite_waiter-stamp");

File::create(anchor).unwrap();
generate_completions(target_dir.as_os_str());
}

fn generate_completions(target_dir: &OsStr) {
Expand All @@ -46,13 +38,19 @@ fn generate_completions(target_dir: &OsStr) {
Shell::Zsh,
] {
if let Err(err) = clap_complete::generate_to(*shell, &mut cmd, bin_name, target_dir) {
panic!("failed to generate completions for {:?} in {:?}: {:?}", shell, target_dir, err);
panic!(
"failed to generate completions for {:?} in {:?}: {:?}",
shell, target_dir, err
);
}
}

if let Err(err) =
clap_complete::generate_to(clap_complete_fig::Fig, &mut cmd, bin_name, target_dir)
{
panic!("failed to generate completions for fig in {:?}: {:?}", target_dir, err);
panic!(
"failed to generate completions for fig in {:?}: {:?}",
target_dir, err
);
}
}

0 comments on commit a6e9ceb

Please sign in to comment.