mirror of
https://github.com/BLAKE3-team/BLAKE3
synced 2024-05-12 14:46:15 +02:00
Generate shell completions at build time
This commit is contained in:
parent
7f2e247f55
commit
bc8f110192
|
@ -75,6 +75,7 @@ dependencies = [
|
|||
"anyhow",
|
||||
"blake3",
|
||||
"clap",
|
||||
"clap_complete",
|
||||
"clap_mangen",
|
||||
"duct",
|
||||
"hex",
|
||||
|
@ -137,6 +138,15 @@ dependencies = [
|
|||
"terminal_size",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_complete"
|
||||
version = "4.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd79504325bf38b10165b02e89b4347300f855f273c4cb30c4a3209e6583275e"
|
||||
dependencies = [
|
||||
"clap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.5.0"
|
||||
|
|
|
@ -28,4 +28,5 @@ tempfile = "3.1.0"
|
|||
[build-dependencies]
|
||||
blake3 = { version = "1", path = ".." }
|
||||
clap = { version = "4.0.8", features = ["derive"] }
|
||||
clap_complete = "4.5.2"
|
||||
clap_mangen = "0.2.20"
|
||||
|
|
|
@ -2,6 +2,23 @@ use clap::CommandFactory;
|
|||
|
||||
include!("src/cli.rs");
|
||||
|
||||
fn generate_completions(out_dir: &std::path::Path) -> std::io::Result<()> {
|
||||
fn generate_to(
|
||||
gen: impl clap_complete::Generator,
|
||||
out_dir: &std::path::Path,
|
||||
) -> std::io::Result<std::path::PathBuf> {
|
||||
let mut command = Inner::command();
|
||||
clap_complete::generate_to(gen, &mut command, "b3sum", out_dir)
|
||||
}
|
||||
|
||||
generate_to(clap_complete::Shell::Bash, out_dir)?;
|
||||
generate_to(clap_complete::Shell::Elvish, out_dir)?;
|
||||
generate_to(clap_complete::Shell::Fish, out_dir)?;
|
||||
generate_to(clap_complete::Shell::PowerShell, out_dir)?;
|
||||
generate_to(clap_complete::Shell::Zsh, out_dir)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn generate_man_page(out_dir: &std::path::Path) -> std::io::Result<()> {
|
||||
let command = Inner::command();
|
||||
|
||||
|
@ -54,6 +71,7 @@ fn main() -> std::io::Result<()> {
|
|||
let out_dir = std::env::var("OUT_DIR").expect("environment variable `OUT_DIR` not defined");
|
||||
let out_dir = std::path::PathBuf::from(out_dir);
|
||||
|
||||
generate_completions(&out_dir)?;
|
||||
generate_man_page(&out_dir)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use clap::Parser;
|
||||
use clap::{Parser, ValueHint};
|
||||
use std::path::PathBuf;
|
||||
|
||||
const DERIVE_KEY_ARG: &str = "derive_key";
|
||||
|
@ -17,6 +17,7 @@ pub struct Inner {
|
|||
/// Files to hash, or checkfiles to check
|
||||
///
|
||||
/// When no file is given, or when - is given, read standard input.
|
||||
#[arg(value_hint(ValueHint::FilePath))]
|
||||
pub file: Vec<PathBuf>,
|
||||
|
||||
/// Use the keyed mode, reading the 32-byte key from stdin
|
||||
|
|
Loading…
Reference in New Issue