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

12
rust/Cargo.lock generated
View File

@@ -127,6 +127,15 @@ dependencies = [
"terminal_size",
]
[[package]]
name = "clap_complete"
version = "4.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f6b5c519bab3ea61843a7923d074b04245624bb84a64a8c150f5deb014e388b"
dependencies = [
"clap",
]
[[package]]
name = "clap_derive"
version = "4.3.2"
@@ -403,6 +412,7 @@ name = "pvapconfig"
version = "0.10.0"
dependencies = [
"clap",
"clap_complete",
"lazy_static",
"openssl",
"rand",
@@ -420,6 +430,7 @@ dependencies = [
"anyhow",
"byteorder",
"clap",
"clap_complete",
"log",
"s390_pv",
"serde",
@@ -434,6 +445,7 @@ version = "0.10.0"
dependencies = [
"anyhow",
"clap",
"clap_complete",
"log",
"s390_pv",
"serde_yaml",

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
rust/pvapconfig/build.rs Normal file
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(())
}

View File

@@ -15,3 +15,10 @@ zerocopy = { version="0.7", features = ["derive"] }
pv = { path = "../pv", package = "s390_pv" }
utils = { path = "../utils" }
[build-dependencies]
clap = { version ="4.1", features = ["derive", "wrap_help"]}
clap_complete = "4.1"
log = { version = "0.4", features = ["std", "release_max_level_debug"] }
utils = { path = "../utils" }

25
rust/pvattest/build.rs Normal file
View File

@@ -0,0 +1,25 @@
// SPDX-License-Identifier: MIT
//
// Copyright IBM Corp. 2024
// it under the terms of the MIT license. See LICENSE for details.
use clap::CommandFactory;
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 = CliOptions::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");
println!("cargo:rerun-if-changed=../utils/src/cli.rs");
Ok(())
}

View File

@@ -12,3 +12,10 @@ serde_yaml = "0.9"
pv = { path = "../pv" , package = "s390_pv" }
utils = { path = "../utils"}
[build-dependencies]
clap = { version ="4.1", features = ["derive", "wrap_help"]}
clap_complete = "4.1"
log = { version = "0.4", features = ["std", "release_max_level_debug"] }
utils = { path = "../utils" }

24
rust/pvsecret/build.rs Normal file
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_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 = CliOptions::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");
println!("cargo:rerun-if-changed=../utils/src/cli.rs");
Ok(())
}