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:
Arkadiy Paronyan
2019-12-20 16:05:01 +01:00
committed by Bastian Köcher
parent bfad5f3ffc
commit 9950ea98fc
6 changed files with 47 additions and 69 deletions
+4 -49
View File
@@ -14,24 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use crate::traits::{AugmentClap, GetLogFilter};
use crate::traits::{AugmentClap, GetSharedParams};
use std::{str::FromStr, path::PathBuf};
use structopt::{StructOpt, clap::{arg_enum, App, AppSettings, SubCommand, Arg}};
pub use crate::execution_strategy::ExecutionStrategy;
/// Auxiliary macro to implement `GetLogFilter` for all types that have the `shared_params` field.
macro_rules! impl_get_log_filter {
( $type:ident ) => {
impl $crate::GetLogFilter for $type {
fn get_log_filter(&self) -> Option<String> {
self.shared_params.get_log_filter()
}
}
}
}
impl Into<sc_client_api::ExecutionStrategy> for ExecutionStrategy {
fn into(self) -> sc_client_api::ExecutionStrategy {
match self {
@@ -153,12 +142,6 @@ pub struct ImportParams {
pub state_cache_size: usize,
}
impl GetLogFilter for SharedParams {
fn get_log_filter(&self) -> Option<String> {
self.log.clone()
}
}
/// Parameters used to create the network configuration.
#[derive(Debug, StructOpt, Clone)]
pub struct NetworkConfigurationParams {
@@ -723,7 +706,6 @@ fn parse_cors(s: &str) -> Result<Cors, Box<dyn std::error::Error>> {
}
impl_augment_clap!(RunCmd);
impl_get_log_filter!(RunCmd);
/// The `build-spec` command used to build a specification.
#[derive(Debug, StructOpt, Clone)]
@@ -748,8 +730,6 @@ pub struct BuildSpecCmd {
pub node_key_params: NodeKeyParams,
}
impl_get_log_filter!(BuildSpecCmd);
/// Wrapper type of `String` which holds an arbitary sized unsigned integer formatted as decimal.
#[derive(Debug, Clone)]
pub struct BlockNumber(String);
@@ -813,8 +793,6 @@ pub struct ExportBlocksCmd {
pub shared_params: SharedParams,
}
impl_get_log_filter!(ExportBlocksCmd);
/// The `import-blocks` command used to import blocks.
#[derive(Debug, StructOpt, Clone)]
pub struct ImportBlocksCmd {
@@ -837,8 +815,6 @@ pub struct ImportBlocksCmd {
pub import_params: ImportParams,
}
impl_get_log_filter!(ImportBlocksCmd);
/// The `check-block` command used to validate blocks.
#[derive(Debug, StructOpt, Clone)]
pub struct CheckBlockCmd {
@@ -861,8 +837,6 @@ pub struct CheckBlockCmd {
pub import_params: ImportParams,
}
impl_get_log_filter!(CheckBlockCmd);
/// The `revert` command used revert the chain to a previous state.
#[derive(Debug, StructOpt, Clone)]
pub struct RevertCmd {
@@ -875,8 +849,6 @@ pub struct RevertCmd {
pub shared_params: SharedParams,
}
impl_get_log_filter!(RevertCmd);
/// The `purge-chain` command used to remove the whole chain.
#[derive(Debug, StructOpt, Clone)]
pub struct PurgeChainCmd {
@@ -889,8 +861,6 @@ pub struct PurgeChainCmd {
pub shared_params: SharedParams,
}
impl_get_log_filter!(PurgeChainCmd);
/// All core commands that are provided by default.
///
/// The core commands are split into multiple subcommands and `Run` is the default subcommand. From
@@ -924,7 +894,7 @@ pub enum CoreParams<CC, RP> {
}
impl<CC, RP> StructOpt for CoreParams<CC, RP> where
CC: StructOpt + GetLogFilter,
CC: StructOpt + GetSharedParams,
RP: StructOpt + AugmentClap
{
fn clap<'a, 'b>() -> App<'a, 'b> {
@@ -979,21 +949,6 @@ impl<CC, RP> StructOpt for CoreParams<CC, RP> where
}
}
impl<CC, RP> GetLogFilter for CoreParams<CC, RP> where CC: GetLogFilter {
fn get_log_filter(&self) -> Option<String> {
match self {
CoreParams::Run(c) => c.left.get_log_filter(),
CoreParams::BuildSpec(c) => c.get_log_filter(),
CoreParams::ExportBlocks(c) => c.get_log_filter(),
CoreParams::ImportBlocks(c) => c.get_log_filter(),
CoreParams::CheckBlock(c) => c.get_log_filter(),
CoreParams::PurgeChain(c) => c.get_log_filter(),
CoreParams::Revert(c) => c.get_log_filter(),
CoreParams::Custom(c) => c.get_log_filter(),
}
}
}
/// A special commandline parameter that expands to nothing.
/// Should be used as custom subcommand/run arguments if no custom values are required.
#[derive(Clone, Debug, Default)]
@@ -1015,8 +970,8 @@ impl AugmentClap for NoCustom {
}
}
impl GetLogFilter for NoCustom {
fn get_log_filter(&self) -> Option<String> {
impl GetSharedParams for NoCustom {
fn shared_params(&self) -> Option<&SharedParams> {
None
}
}