Skip to content

Commit

Permalink
node: add command line completion
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianFranzen committed Jul 18, 2024
1 parent 7924653 commit 0931e71
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 10 deletions.
20 changes: 15 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,17 @@ testnet-runtime.workspace = true
#try-runtime-core = { git = "https://github.com/paritytech/try-runtime-cli", tag = "v0.7.0", optional = true }

[build-dependencies]
polkadot-sdk = { workspace = true, features = [ "substrate-build-script-utils" ] }
clap.workspace = true

clap_complete = "4.5"

polkadot-sdk = { workspace = true, features = [
"substrate-build-script-utils",
"frame-benchmarking-cli",
"sc-cli",
"sc-storage-monitor",
"staging-node-inspect",
] }

[features]
default = [ "std" ]
Expand Down
49 changes: 45 additions & 4 deletions node/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,48 @@
use polkadot_sdk::substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed};

fn main() {
generate_cargo_keys();
cli::main();
}

mod cli {
include!("src/cli.rs");

use clap::{CommandFactory, ValueEnum};
use clap_complete::{generate_to, Shell};
use polkadot_sdk::substrate_build_script_utils::{
generate_cargo_keys, rerun_if_git_head_changed,
};
use std::{env, fs, path::Path};

pub fn main() {
build_shell_completion();
generate_cargo_keys();

rerun_if_git_head_changed();
}

/// Build shell completion scripts for all known shells.
fn build_shell_completion() {
for shell in Shell::value_variants() {
build_completion(shell);
}
}

/// Build the shell auto-completion for a given Shell.
fn build_completion(shell: &Shell) {
let outdir = match env::var_os("OUT_DIR") {
None => return,
Some(dir) => dir,
};
let path = Path::new(&outdir)
.parent()
.unwrap()
.parent()
.unwrap()
.parent()
.unwrap()
.join("completion-scripts");

fs::create_dir(&path).ok();

rerun_if_git_head_changed();
let _ = generate_to(*shell, &mut Cli::command(), "timechain-node", &path);
}
}

0 comments on commit 0931e71

Please sign in to comment.