rust: Generate shell (e.g. bash) completion scripts via build.rs for all tools

It might be handy to have shell completion support for the Rust PV
tools.

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
This commit is contained in:
Marc Hartmayer
2024-05-24 09:40:22 +00:00
committed by Steffen Eiden
parent 4d2c92f6d5
commit f83af8e076
7 changed files with 104 additions and 0 deletions
+5
View File
@@ -16,3 +16,8 @@ regex = "1.7"
serde = { version = "1.0.139", features = ["derive"] }
serde_yaml = "0.9"
utils = { path = "../utils" }
[build-dependencies]
clap = { version ="4.1", features = ["derive", "wrap_help"]}
clap_complete = "4.1"
lazy_static = "1.1"
+24
View File
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
//
// Copyright IBM Corp. 2024
// it under the terms of the MIT license. See LICENSE for details.
use clap::{CommandFactory, ValueEnum};
use clap_complete::{generate_to, Shell};
use std::env;
use std::io::Error;
include!("src/cli.rs");
fn main() -> Result<(), Error> {
let outdir = env::var_os("OUT_DIR").unwrap();
let crate_name = env!("CARGO_PKG_NAME");
let mut cmd = Cli::command();
for &shell in Shell::value_variants() {
generate_to(shell, &mut cmd, crate_name, &outdir)?;
}
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=src/cli.rs");
Ok(())
}