mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 00:17:56 +00:00
Fix CLI setup again (#4851)
* Fix CLI setup again We need to set `config_dir` and `database_path` for almost every command. This fixes `purge-chain` and also adds a test to make sure we don't break it again. * Adds missing test files * Split methods
This commit is contained in:
@@ -234,7 +234,7 @@ where
|
||||
SF: AbstractService + Unpin,
|
||||
{
|
||||
init(&run_cmd.shared_params, version)?;
|
||||
load_spec(&mut config, &run_cmd.shared_params, spec_factory)?;
|
||||
init_config(&mut config, &run_cmd.shared_params, version, spec_factory)?;
|
||||
run_cmd.run(config, new_light, new_full, version)
|
||||
}
|
||||
|
||||
@@ -257,9 +257,8 @@ where
|
||||
<BB as BlockT>::Hash: std::str::FromStr,
|
||||
{
|
||||
let shared_params = subcommand.get_shared_params();
|
||||
|
||||
init(shared_params, version)?;
|
||||
load_spec(&mut config, shared_params, spec_factory)?;
|
||||
init_config(&mut config, shared_params, version, spec_factory)?;
|
||||
subcommand.run(config, builder)
|
||||
}
|
||||
|
||||
@@ -267,9 +266,9 @@ where
|
||||
///
|
||||
/// This method:
|
||||
///
|
||||
/// 1. set the panic handler
|
||||
/// 2. raise the FD limit
|
||||
/// 3. initialize the logger
|
||||
/// 1. Set the panic handler
|
||||
/// 2. Raise the FD limit
|
||||
/// 3. Initialize the logger
|
||||
pub fn init(shared_params: &SharedParams, version: &VersionInfo) -> error::Result<()> {
|
||||
let full_version = sc_service::config::full_version_from_strs(
|
||||
version.version,
|
||||
@@ -283,6 +282,37 @@ pub fn init(shared_params: &SharedParams, version: &VersionInfo) -> error::Resul
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Initialize the given `config`.
|
||||
///
|
||||
/// This will load the chain spec, set the `config_dir` and the `database_dir`.
|
||||
pub fn init_config<G, E, F>(
|
||||
config: &mut Configuration<G, E>,
|
||||
shared_params: &SharedParams,
|
||||
version: &VersionInfo,
|
||||
spec_factory: F,
|
||||
) -> error::Result<()> where
|
||||
F: FnOnce(&str) -> Result<Option<ChainSpec<G, E>>, String>,
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
{
|
||||
load_spec(config, shared_params, spec_factory)?;
|
||||
|
||||
if config.config_dir.is_none() {
|
||||
config.config_dir = Some(base_path(&shared_params, version));
|
||||
}
|
||||
|
||||
if config.database.is_none() {
|
||||
config.database = Some(DatabaseConfig::Path {
|
||||
path: config
|
||||
.in_chain_config_dir(DEFAULT_DB_CONFIG_PATH)
|
||||
.expect("We provided a base_path/config_dir."),
|
||||
cache_size: None,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Run the node
|
||||
///
|
||||
/// Builds and runs either a full or a light node, depending on the `role` within the `Configuration`.
|
||||
@@ -514,26 +544,10 @@ where
|
||||
pub fn update_config_for_running_node<G, E>(
|
||||
mut config: &mut Configuration<G, E>,
|
||||
cli: RunCmd,
|
||||
version: &VersionInfo,
|
||||
) -> error::Result<()>
|
||||
where
|
||||
G: RuntimeGenesis,
|
||||
{
|
||||
if config.config_dir.is_none() {
|
||||
config.config_dir = Some(base_path(&cli.shared_params, version));
|
||||
}
|
||||
|
||||
if config.database.is_none() {
|
||||
// NOTE: the loading of the DatabaseConfig is voluntarily delayed to here
|
||||
// in case config.config_dir has been customized
|
||||
config.database = Some(DatabaseConfig::Path {
|
||||
path: config
|
||||
.in_chain_config_dir(DEFAULT_DB_CONFIG_PATH)
|
||||
.expect("We provided a base_path/config_dir."),
|
||||
cache_size: None,
|
||||
});
|
||||
}
|
||||
|
||||
fill_config_keystore_password_and_path(&mut config, &cli)?;
|
||||
|
||||
let keyring = cli.get_keyring();
|
||||
@@ -790,7 +804,6 @@ mod tests {
|
||||
update_config_for_running_node(
|
||||
&mut node_config,
|
||||
run_cmds.clone(),
|
||||
TEST_VERSION_INFO,
|
||||
).unwrap();
|
||||
|
||||
let expected_path = match keystore_path {
|
||||
@@ -843,8 +856,14 @@ mod tests {
|
||||
let cli = RunCmd::from_iter(args);
|
||||
|
||||
let mut config = Configuration::new(TEST_VERSION_INFO);
|
||||
config.chain_spec = Some(chain_spec);
|
||||
update_config_for_running_node(&mut config, cli, TEST_VERSION_INFO).unwrap();
|
||||
init(&cli.shared_params, &TEST_VERSION_INFO).unwrap();
|
||||
init_config(
|
||||
&mut config,
|
||||
&cli.shared_params,
|
||||
&TEST_VERSION_INFO,
|
||||
|_| Ok(Some(chain_spec)),
|
||||
).unwrap();
|
||||
update_config_for_running_node(&mut config, cli).unwrap();
|
||||
|
||||
assert!(config.config_dir.is_some());
|
||||
assert!(config.database.is_some());
|
||||
|
||||
@@ -933,11 +933,7 @@ impl RunCmd {
|
||||
{
|
||||
assert!(config.chain_spec.is_some(), "chain_spec must be present before continuing");
|
||||
|
||||
crate::update_config_for_running_node(
|
||||
&mut config,
|
||||
self,
|
||||
&version,
|
||||
)?;
|
||||
crate::update_config_for_running_node(&mut config, self)?;
|
||||
|
||||
crate::run_node(config, new_light, new_full, &version)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user