pub trait SubstrateCli: Sized {
Show 16 methods
// Required methods
fn impl_name() -> String;
fn impl_version() -> String;
fn description() -> String;
fn author() -> String;
fn support_url() -> String;
fn copyright_start_year() -> i32;
fn load_spec(&self, id: &str) -> Result<Box<dyn ChainSpec>, String>;
// Provided methods
fn executable_name() -> String { ... }
fn from_args() -> Self
where Self: Parser + Sized { ... }
fn from_iter<I>(iter: I) -> Self
where Self: Parser + Sized,
I: IntoIterator,
I::Item: Into<OsString> + Clone { ... }
fn try_from_iter<I>(iter: I) -> Result<Self>
where Self: Parser + Sized,
I: IntoIterator,
I::Item: Into<OsString> + Clone { ... }
fn client_id() -> String { ... }
fn create_configuration<T: CliConfiguration<DVC>, DVC: DefaultConfigurationValues>(
&self,
command: &T,
tokio_handle: Handle,
) -> Result<Configuration> { ... }
fn create_runner<T: CliConfiguration<DVC>, DVC: DefaultConfigurationValues>(
&self,
command: &T,
) -> Result<Runner<Self>> { ... }
fn create_runner_with_logger_hook<T: CliConfiguration<DVC>, DVC: DefaultConfigurationValues, F>(
&self,
command: &T,
logger_hook: F,
) -> Result<Runner<Self>>
where F: FnOnce(&mut LoggerBuilder, &Configuration) { ... }
fn setup_command(cmd: Command) -> Command { ... }
}
Expand description
Substrate client CLI
This trait needs to be implemented on the root CLI struct of the application. It will provide
the implementation name
, version
, executable name
, description
, author
, support_url
,
copyright start year
and most importantly: how to load the chain spec.
Required Methods§
Sourcefn impl_version() -> String
fn impl_version() -> String
Implementation version.
By default, it will look like this:
2.0.0-b950f731c
Where the hash is the short hash of the commit in the Git repository.
Sourcefn description() -> String
fn description() -> String
Executable file description.
Executable file author.
Sourcefn support_url() -> String
fn support_url() -> String
Support URL.
Sourcefn copyright_start_year() -> i32
fn copyright_start_year() -> i32
Copyright starting year (x-current year)
Provided Methods§
Sourcefn executable_name() -> String
fn executable_name() -> String
Executable file name.
Extracts the file name from std::env::current_exe()
.
Resorts to the env var CARGO_PKG_NAME
in case of Error.
Sourcefn from_args() -> Selfwhere
Self: Parser + Sized,
fn from_args() -> Selfwhere
Self: Parser + Sized,
Helper function used to parse the command line arguments. This is the equivalent of
[clap::Parser::parse()
].
To allow running the node without subcommand, it also sets a few more settings:
[clap::Command::propagate_version
], [clap::Command::args_conflicts_with_subcommands
],
[clap::Command::subcommand_negates_reqs
].
Creates Self
from the command line arguments. Print the
error message and quit the program in case of failure.
Sourcefn from_iter<I>(iter: I) -> Self
fn from_iter<I>(iter: I) -> Self
Helper function used to parse the command line arguments. This is the equivalent of
[clap::Parser::parse_from
].
To allow running the node without subcommand, it also sets a few more settings:
[clap::Command::propagate_version
], [clap::Command::args_conflicts_with_subcommands
],
[clap::Command::subcommand_negates_reqs
].
Creates Self
from any iterator over arguments.
Print the error message and quit the program in case of failure.
Sourcefn try_from_iter<I>(iter: I) -> Result<Self>
fn try_from_iter<I>(iter: I) -> Result<Self>
Helper function used to parse the command line arguments. This is the equivalent of
[clap::Parser::try_parse_from
]
To allow running the node without subcommand, it also sets a few more settings:
[clap::Command::propagate_version
], [clap::Command::args_conflicts_with_subcommands
],
[clap::Command::subcommand_negates_reqs
].
Creates Self
from any iterator over arguments.
Print the error message and quit the program in case of failure.
NOTE: This method WILL NOT exit when --help
or --version
(or short versions) are
used. It will return a [clap::Error
], where the [clap::Error::kind
] is a
[clap::error::ErrorKind::DisplayHelp
] or [clap::error::ErrorKind::DisplayVersion
]
respectively. You must call [clap::Error::exit
] or perform a std::process::exit
.
Sourcefn create_configuration<T: CliConfiguration<DVC>, DVC: DefaultConfigurationValues>(
&self,
command: &T,
tokio_handle: Handle,
) -> Result<Configuration>
fn create_configuration<T: CliConfiguration<DVC>, DVC: DefaultConfigurationValues>( &self, command: &T, tokio_handle: Handle, ) -> Result<Configuration>
Only create a Configuration for the command provided in argument
Sourcefn create_runner<T: CliConfiguration<DVC>, DVC: DefaultConfigurationValues>(
&self,
command: &T,
) -> Result<Runner<Self>>
fn create_runner<T: CliConfiguration<DVC>, DVC: DefaultConfigurationValues>( &self, command: &T, ) -> Result<Runner<Self>>
Create a runner for the command provided in argument. This will create a Configuration and a tokio runtime
Sourcefn create_runner_with_logger_hook<T: CliConfiguration<DVC>, DVC: DefaultConfigurationValues, F>(
&self,
command: &T,
logger_hook: F,
) -> Result<Runner<Self>>where
F: FnOnce(&mut LoggerBuilder, &Configuration),
fn create_runner_with_logger_hook<T: CliConfiguration<DVC>, DVC: DefaultConfigurationValues, F>(
&self,
command: &T,
logger_hook: F,
) -> Result<Runner<Self>>where
F: FnOnce(&mut LoggerBuilder, &Configuration),
Create a runner for the command provided in argument. The logger_hook
can be used to setup
a custom profiler or update the logger configuration before it is initialized.
Example:
use sc_tracing::{SpanDatum, TraceEvent};
struct TestProfiler;
impl sc_tracing::TraceHandler for TestProfiler {
fn handle_span(&self, sd: &SpanDatum) {}
fn handle_event(&self, _event: &TraceEvent) {}
};
fn logger_hook() -> impl FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration) -> () {
|logger_builder, config| {
logger_builder.with_custom_profiling(Box::new(TestProfiler{}));
}
}
Sourcefn setup_command(cmd: Command) -> Command
fn setup_command(cmd: Command) -> Command
Augments a clap::Command
with standard metadata like name, version, author, description,
etc.
This is used internally in from_iter
, try_from_iter
and can be used externally
to manually set up a command with Substrate CLI defaults.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.