Skip to content

Commit

Permalink
Deduplicate create_runner() logic
Browse files Browse the repository at this point in the history
  • Loading branch information
serban300 committed Jul 1, 2024
1 parent 283d474 commit 270060b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion polkadot/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ where
F: FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration),
{
let runner = cli
.create_runner_with_logger_hook::<sc_cli::RunCmd, F>(&cli.run.base, logger_hook)
.create_runner_with_logger_hook::<_, _, F>(&cli.run.base, logger_hook)
.map_err(Error::from)?;
let chain_spec = &runner.config().chain_spec;

Expand Down
21 changes: 8 additions & 13 deletions substrate/client/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,8 @@ pub trait SubstrateCli: Sized {
fn create_runner<T: CliConfiguration<DVC>, DVC: DefaultConfigurationValues>(
&self,
command: &T,
) -> error::Result<Runner<Self>> {
let tokio_runtime = build_runtime()?;

// `capture` needs to be called in a tokio context.
// Also capture them as early as possible.
let signals = tokio_runtime.block_on(async { Signals::capture() })?;

let config = command.create_configuration(self, tokio_runtime.handle().clone())?;

command.init(&Self::support_url(), &Self::impl_version(), |_, _| {}, &config)?;
Runner::new(config, tokio_runtime, signals)
) -> Result<Runner<Self>> {
self.create_runner_with_logger_hook(command, |_, _| {})
}

/// Create a runner for the command provided in argument. The `logger_hook` can be used to setup
Expand All @@ -231,11 +222,15 @@ pub trait SubstrateCli: Sized {
/// }
/// }
/// ```
fn create_runner_with_logger_hook<T: CliConfiguration, F>(
fn create_runner_with_logger_hook<
T: CliConfiguration<DVC>,
DVC: DefaultConfigurationValues,
F,
>(
&self,
command: &T,
logger_hook: F,
) -> error::Result<Runner<Self>>
) -> Result<Runner<Self>>
where
F: FnOnce(&mut LoggerBuilder, &Configuration),
{
Expand Down

0 comments on commit 270060b

Please sign in to comment.