mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 23:37:56 +00:00
Shared params in CLI API (#4466)
* Common shared parames getter * Expose more types from `service-builder` Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
committed by
Bastian Köcher
parent
bfad5f3ffc
commit
9950ea98fc
@@ -57,7 +57,7 @@ use params::{
|
||||
NodeKeyParams, NodeKeyType, Cors, CheckBlockCmd,
|
||||
};
|
||||
pub use params::{NoCustom, CoreParams, SharedParams, ImportParams, ExecutionStrategy};
|
||||
pub use traits::{GetLogFilter, AugmentClap};
|
||||
pub use traits::{GetSharedParams, AugmentClap};
|
||||
use app_dirs::{AppInfo, AppDataType};
|
||||
use log::info;
|
||||
use lazy_static::lazy_static;
|
||||
@@ -195,7 +195,7 @@ pub fn parse_and_prepare<'a, CC, RP, I>(
|
||||
args: I,
|
||||
) -> ParseAndPrepare<'a, CC, RP>
|
||||
where
|
||||
CC: StructOpt + Clone + GetLogFilter,
|
||||
CC: StructOpt + Clone + GetSharedParams,
|
||||
RP: StructOpt + Clone + AugmentClap,
|
||||
I: IntoIterator,
|
||||
<I as IntoIterator>::Item: Into<std::ffi::OsString> + Clone,
|
||||
@@ -216,10 +216,9 @@ where
|
||||
.setting(AppSettings::SubcommandsNegateReqs)
|
||||
.get_matches_from(args);
|
||||
let cli_args = CoreParams::<CC, RP>::from_clap(&matches);
|
||||
init_logger(cli_args.get_log_filter().as_ref().map(|v| v.as_ref()).unwrap_or(""));
|
||||
fdlimit::raise_fd_limit();
|
||||
|
||||
match cli_args {
|
||||
let args = match cli_args {
|
||||
params::CoreParams::Run(params) => ParseAndPrepare::Run(
|
||||
ParseAndPrepareRun { params, impl_name, version }
|
||||
),
|
||||
@@ -242,7 +241,9 @@ where
|
||||
ParseAndPrepareRevert { params, version }
|
||||
),
|
||||
params::CoreParams::Custom(params) => ParseAndPrepare::CustomCommand(params),
|
||||
}
|
||||
};
|
||||
init_logger(args.shared_params().and_then(|p| p.log.as_ref()).map(|v| v.as_ref()).unwrap_or(""));
|
||||
args
|
||||
}
|
||||
|
||||
/// Returns a string displaying the node role, special casing the sentry mode
|
||||
@@ -277,6 +278,22 @@ pub enum ParseAndPrepare<'a, CC, RP> {
|
||||
CustomCommand(CC),
|
||||
}
|
||||
|
||||
impl<'a, CC, RP> ParseAndPrepare<'a, CC, RP> where CC: GetSharedParams {
|
||||
/// Return common set of parameters shared by all commands.
|
||||
pub fn shared_params(&self) -> Option<&SharedParams> {
|
||||
match self {
|
||||
ParseAndPrepare::Run(c) => Some(&c.params.left.shared_params),
|
||||
ParseAndPrepare::BuildSpec(c) => Some(&c.params.shared_params),
|
||||
ParseAndPrepare::ExportBlocks(c) => Some(&c.params.shared_params),
|
||||
ParseAndPrepare::ImportBlocks(c) => Some(&c.params.shared_params),
|
||||
ParseAndPrepare::CheckBlock(c) => Some(&c.params.shared_params),
|
||||
ParseAndPrepare::PurgeChain(c) => Some(&c.params.shared_params),
|
||||
ParseAndPrepare::RevertChain(c) => Some(&c.params.shared_params),
|
||||
ParseAndPrepare::CustomCommand(c) => c.shared_params(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Command ready to run the main client.
|
||||
pub struct ParseAndPrepareRun<'a, RP> {
|
||||
params: MergeParameters<RunCmd, RP>,
|
||||
|
||||
Reference in New Issue
Block a user