mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-21 18:01:07 +00:00
CLI API refactoring and improvement (#4692)
It changes the way we extended the CLI functionalities of substrate to allow more flexibility. (If this was not clear, here is another version: it changes the `sc_cli` API to allow more flexibility).
This touches a few important things:
- the startup of the async task with tokei:
This was in node and node-template and I moved it to substrate. The idea is to have 1 time the code that handles unix signals (SIGTERM and SIGINT) properly. It is however possible to make this more generic to wait for a future instead and provide only a helper for the basic handling of SIGTERM and SIGINT.
- increased the version of structopt and tokei
- no more use of structopt internal's API
- less use of generics
Related to #4643 and https://github.com/paritytech/cumulus/pull/42: the implementation of "into_configuration" and "get_config" are similar but with better flexibility so it is now possible in cumulus to have the command-line arguments only of the run command for polkadot if we want
Related to https://github.com/paritytech/cumulus/issues/24 and https://github.com/paritytech/cumulus/issues/34 : it will now be possible to make a configuration struct for polkadot with some overrides of the default parameters much more easily.
This commit is contained in:
@@ -14,39 +14,48 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::{fs, env, path::Path};
|
||||
use structopt::{StructOpt, clap::Shell};
|
||||
use sc_cli::{NoCustom, CoreParams};
|
||||
use vergen::{ConstantsFlags, generate_cargo_keys};
|
||||
|
||||
fn main() {
|
||||
build_shell_completion();
|
||||
generate_cargo_keys(ConstantsFlags::all()).expect("Failed to generate metadata files");
|
||||
|
||||
build_script_utils::rerun_if_git_head_changed();
|
||||
#[cfg(feature = "cli")]
|
||||
cli::main();
|
||||
}
|
||||
|
||||
/// Build shell completion scripts for all known shells
|
||||
/// Full list in https://github.com/kbknapp/clap-rs/blob/e9d0562a1dc5dfe731ed7c767e6cee0af08f0cf9/src/app/parser.rs#L123
|
||||
fn build_shell_completion() {
|
||||
for shell in &[Shell::Bash, Shell::Fish, Shell::Zsh, Shell::Elvish, Shell::PowerShell] {
|
||||
build_completion(shell);
|
||||
#[cfg(feature = "cli")]
|
||||
mod cli {
|
||||
include!("src/cli.rs");
|
||||
|
||||
use std::{fs, env, path::Path};
|
||||
use sc_cli::{structopt::clap::Shell};
|
||||
use vergen::{ConstantsFlags, generate_cargo_keys};
|
||||
|
||||
pub fn main() {
|
||||
build_shell_completion();
|
||||
generate_cargo_keys(ConstantsFlags::all()).expect("Failed to generate metadata files");
|
||||
|
||||
build_script_utils::rerun_if_git_head_changed();
|
||||
}
|
||||
|
||||
/// Build shell completion scripts for all known shells
|
||||
/// Full list in https://github.com/kbknapp/clap-rs/blob/e9d0562a1dc5dfe731ed7c767e6cee0af08f0cf9/src/app/parser.rs#L123
|
||||
fn build_shell_completion() {
|
||||
for shell in &[Shell::Bash, Shell::Fish, Shell::Zsh, Shell::Elvish, Shell::PowerShell] {
|
||||
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();
|
||||
|
||||
Cli::clap().gen_completions("substrate-node", *shell, &path);
|
||||
}
|
||||
}
|
||||
|
||||
/// 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();
|
||||
|
||||
CoreParams::<NoCustom, NoCustom>::clap().gen_completions("substrate-node", *shell, &path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user