mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 15:47:58 +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:
@@ -0,0 +1,82 @@
|
||||
// Copyright 2017-2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use sc_cli::{VersionInfo, error};
|
||||
use sc_service::{Roles as ServiceRoles};
|
||||
use node_transaction_factory::RuntimeAdapter;
|
||||
use crate::{Cli, service, ChainSpec, load_spec, Subcommand, factory_impl::FactoryState};
|
||||
|
||||
/// Parse command line arguments into service configuration.
|
||||
pub fn run<I, T>(args: I, version: sc_cli::VersionInfo) -> error::Result<()>
|
||||
where
|
||||
I: Iterator<Item = T>,
|
||||
T: Into<std::ffi::OsString> + Clone,
|
||||
{
|
||||
let args: Vec<_> = args.collect();
|
||||
let opt = sc_cli::from_iter::<Cli, _>(args.clone(), &version);
|
||||
|
||||
let mut config = sc_service::Configuration::default();
|
||||
config.impl_name = "substrate-node";
|
||||
|
||||
match opt.subcommand {
|
||||
None => sc_cli::run(
|
||||
config,
|
||||
opt.run,
|
||||
service::new_light,
|
||||
service::new_full,
|
||||
load_spec,
|
||||
&version,
|
||||
),
|
||||
Some(Subcommand::Factory(cli_args)) => {
|
||||
sc_cli::init(&mut config, load_spec, &cli_args.shared_params, &version)?;
|
||||
|
||||
sc_cli::fill_import_params(
|
||||
&mut config,
|
||||
&cli_args.import_params,
|
||||
ServiceRoles::FULL,
|
||||
cli_args.shared_params.dev,
|
||||
)?;
|
||||
|
||||
match ChainSpec::from(config.expect_chain_spec().id()) {
|
||||
Some(ref c) if c == &ChainSpec::Development || c == &ChainSpec::LocalTestnet => {},
|
||||
_ => panic!("Factory is only supported for development and local testnet."),
|
||||
}
|
||||
|
||||
let factory_state = FactoryState::new(
|
||||
cli_args.mode.clone(),
|
||||
cli_args.num,
|
||||
cli_args.rounds,
|
||||
);
|
||||
|
||||
let service_builder = new_full_start!(config).0;
|
||||
node_transaction_factory::factory::<FactoryState<_>, _, _, _, _, _>(
|
||||
factory_state,
|
||||
service_builder.client(),
|
||||
service_builder.select_chain()
|
||||
.expect("The select_chain is always initialized by new_full_start!; QED")
|
||||
).map_err(|e| format!("Error in transaction factory: {}", e))?;
|
||||
|
||||
Ok(())
|
||||
},
|
||||
Some(Subcommand::Base(subcommand)) => sc_cli::run_subcommand(
|
||||
config,
|
||||
subcommand,
|
||||
load_spec,
|
||||
|config: service::NodeConfiguration| Ok(new_full_start!(config).0),
|
||||
&version,
|
||||
),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user