Skip to content

Commit f83af8e

Browse files
mhartmaysteffen-eiden
authored andcommitted
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 <[email protected]> Signed-off-by: Marc Hartmayer <[email protected]> Signed-off-by: Steffen Eiden <[email protected]>
1 parent 4d2c92f commit f83af8e

File tree

7 files changed

+104
-0
lines changed

7 files changed

+104
-0
lines changed

rust/Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/pvapconfig/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ regex = "1.7"
1616
serde = { version = "1.0.139", features = ["derive"] }
1717
serde_yaml = "0.9"
1818
utils = { path = "../utils" }
19+
20+
[build-dependencies]
21+
clap = { version ="4.1", features = ["derive", "wrap_help"]}
22+
clap_complete = "4.1"
23+
lazy_static = "1.1"

rust/pvapconfig/build.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-License-Identifier: MIT
2+
//
3+
// Copyright IBM Corp. 2024
4+
// it under the terms of the MIT license. See LICENSE for details.
5+
6+
use clap::{CommandFactory, ValueEnum};
7+
use clap_complete::{generate_to, Shell};
8+
use std::env;
9+
use std::io::Error;
10+
11+
include!("src/cli.rs");
12+
13+
fn main() -> Result<(), Error> {
14+
let outdir = env::var_os("OUT_DIR").unwrap();
15+
let crate_name = env!("CARGO_PKG_NAME");
16+
let mut cmd = Cli::command();
17+
for &shell in Shell::value_variants() {
18+
generate_to(shell, &mut cmd, crate_name, &outdir)?;
19+
}
20+
21+
println!("cargo:rerun-if-changed=build.rs");
22+
println!("cargo:rerun-if-changed=src/cli.rs");
23+
Ok(())
24+
}

rust/pvattest/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ zerocopy = { version="0.7", features = ["derive"] }
1515

1616
pv = { path = "../pv", package = "s390_pv" }
1717
utils = { path = "../utils" }
18+
19+
[build-dependencies]
20+
clap = { version ="4.1", features = ["derive", "wrap_help"]}
21+
clap_complete = "4.1"
22+
log = { version = "0.4", features = ["std", "release_max_level_debug"] }
23+
24+
utils = { path = "../utils" }

rust/pvattest/build.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: MIT
2+
//
3+
// Copyright IBM Corp. 2024
4+
// it under the terms of the MIT license. See LICENSE for details.
5+
6+
use clap::CommandFactory;
7+
use clap_complete::{generate_to, Shell};
8+
use std::env;
9+
use std::io::Error;
10+
11+
include!("src/cli.rs");
12+
13+
fn main() -> Result<(), Error> {
14+
let outdir = env::var_os("OUT_DIR").unwrap();
15+
let crate_name = env!("CARGO_PKG_NAME");
16+
let mut cmd = CliOptions::command();
17+
for &shell in Shell::value_variants() {
18+
generate_to(shell, &mut cmd, crate_name, &outdir)?;
19+
}
20+
21+
println!("cargo:rerun-if-changed=build.rs");
22+
println!("cargo:rerun-if-changed=src/cli.rs");
23+
println!("cargo:rerun-if-changed=../utils/src/cli.rs");
24+
Ok(())
25+
}

rust/pvsecret/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@ serde_yaml = "0.9"
1212

1313
pv = { path = "../pv" , package = "s390_pv" }
1414
utils = { path = "../utils"}
15+
16+
[build-dependencies]
17+
clap = { version ="4.1", features = ["derive", "wrap_help"]}
18+
clap_complete = "4.1"
19+
log = { version = "0.4", features = ["std", "release_max_level_debug"] }
20+
21+
utils = { path = "../utils" }

rust/pvsecret/build.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-License-Identifier: MIT
2+
//
3+
// Copyright IBM Corp. 2024
4+
// it under the terms of the MIT license. See LICENSE for details.
5+
6+
use clap_complete::{generate_to, Shell};
7+
use std::env;
8+
use std::io::Error;
9+
10+
include!("src/cli.rs");
11+
12+
fn main() -> Result<(), Error> {
13+
let outdir = env::var_os("OUT_DIR").unwrap();
14+
let crate_name = env!("CARGO_PKG_NAME");
15+
let mut cmd = CliOptions::command();
16+
for &shell in Shell::value_variants() {
17+
generate_to(shell, &mut cmd, crate_name, &outdir)?;
18+
}
19+
20+
println!("cargo:rerun-if-changed=build.rs");
21+
println!("cargo:rerun-if-changed=src/cli.rs");
22+
println!("cargo:rerun-if-changed=../utils/src/cli.rs");
23+
Ok(())
24+
}

0 commit comments

Comments
 (0)