Skip to content

Commit

Permalink
build: generate completion scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
moz-sec committed Apr 30, 2024
1 parent 50a76df commit 7763b6c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ categories = ["rust", "cli", "compression", "command-line", "tool"]

[dependencies]
clap = { version = "4.5.4", features = ["derive"] }

[build-dependencies]
clap = { version = "4.5.4", features = ["derive"] }
clap_complete = "4.5.2"
33 changes: 33 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use clap::{Command, CommandFactory};
use clap_complete::Shell;
use std::fs::File;
use std::path::Path;

include!("src/cli.rs");
const APP_NAME: &str = "unicom";

fn generate(s: Shell, app: &mut Command, outdir: &Path, file: &str) {
let destfile = outdir.join(file);
println!("dest: {}", destfile.display());

std::fs::create_dir_all(destfile.parent().unwrap()).unwrap();
let mut dest = File::create(destfile).unwrap();
clap_complete::generate(s, app, APP_NAME, &mut dest);
}

fn main() {
let mut app = Args::command();
app.set_bin_name(APP_NAME);

let outdir = Path::new(env!("CARGO_MANIFEST_DIR")).join("target/completions/");
generate(Shell::Bash, &mut app, &outdir, "unicom-completion.bash");
generate(Shell::Zsh, &mut app, &outdir, "_unicom");
generate(Shell::Fish, &mut app, &outdir, "unicom-completion.fish");
generate(
Shell::PowerShell,
&mut app,
&outdir,
"unicom-completion.ps1",
);
generate(Shell::Elvish, &mut app, &outdir, "unicom-completion.elv");
}

0 comments on commit 7763b6c

Please sign in to comment.