Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit e473c5b

Browse files
authored
Move subcommands from sc-cli to nodes (#6948)
1 parent a7c651c commit e473c5b

File tree

6 files changed

+141
-472
lines changed

6 files changed

+141
-472
lines changed

bin/node-template/node/src/cli.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use structopt::StructOpt;
2-
use sc_cli::{RunCmd, Subcommand};
2+
use sc_cli::RunCmd;
33

44
#[derive(Debug, StructOpt)]
55
pub struct Cli {
@@ -9,3 +9,27 @@ pub struct Cli {
99
#[structopt(flatten)]
1010
pub run: RunCmd,
1111
}
12+
13+
#[derive(Debug, StructOpt)]
14+
pub enum Subcommand {
15+
/// Build a chain specification.
16+
BuildSpec(sc_cli::BuildSpecCmd),
17+
18+
/// Validate blocks.
19+
CheckBlock(sc_cli::CheckBlockCmd),
20+
21+
/// Export blocks.
22+
ExportBlocks(sc_cli::ExportBlocksCmd),
23+
24+
/// Export the state of a given block into a chain spec.
25+
ExportState(sc_cli::ExportStateCmd),
26+
27+
/// Import blocks.
28+
ImportBlocks(sc_cli::ImportBlocksCmd),
29+
30+
/// Remove the whole chain.
31+
PurgeChain(sc_cli::PurgeChainCmd),
32+
33+
/// Revert the chain to a previous state.
34+
Revert(sc_cli::RevertCmd),
35+
}

bin/node-template/node/src/command.rs

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// limitations under the License.
1717

1818
use crate::chain_spec;
19-
use crate::cli::Cli;
19+
use crate::cli::{Cli, Subcommand};
2020
use crate::service;
2121
use sc_cli::{SubstrateCli, RuntimeVersion, Role, ChainSpec};
2222
use sc_service::PartialComponents;
@@ -66,15 +66,55 @@ impl SubstrateCli for Cli {
6666
pub fn run() -> sc_cli::Result<()> {
6767
let cli = Cli::from_args();
6868

69-
match cli.subcommand {
70-
Some(ref subcommand) => {
71-
let runner = cli.create_runner(subcommand)?;
72-
runner.run_subcommand(subcommand, |config| {
73-
let PartialComponents { client, backend, task_manager, import_queue, .. }
69+
match &cli.subcommand {
70+
Some(Subcommand::BuildSpec(cmd)) => {
71+
let runner = cli.create_runner(cmd)?;
72+
runner.sync_run(|config| cmd.run(config.chain_spec, config.network))
73+
},
74+
Some(Subcommand::CheckBlock(cmd)) => {
75+
let runner = cli.create_runner(cmd)?;
76+
runner.async_run(|config| {
77+
let PartialComponents { client, task_manager, import_queue, ..}
7478
= new_partial(&config)?;
75-
Ok((client, backend, import_queue, task_manager))
79+
Ok((cmd.run(client, import_queue), task_manager))
7680
})
77-
}
81+
},
82+
Some(Subcommand::ExportBlocks(cmd)) => {
83+
let runner = cli.create_runner(cmd)?;
84+
runner.async_run(|config| {
85+
let PartialComponents { client, task_manager, ..}
86+
= new_partial(&config)?;
87+
Ok((cmd.run(client, config.database), task_manager))
88+
})
89+
},
90+
Some(Subcommand::ExportState(cmd)) => {
91+
let runner = cli.create_runner(cmd)?;
92+
runner.async_run(|config| {
93+
let PartialComponents { client, task_manager, ..}
94+
= new_partial(&config)?;
95+
Ok((cmd.run(client, config.chain_spec), task_manager))
96+
})
97+
},
98+
Some(Subcommand::ImportBlocks(cmd)) => {
99+
let runner = cli.create_runner(cmd)?;
100+
runner.async_run(|config| {
101+
let PartialComponents { client, task_manager, import_queue, ..}
102+
= new_partial(&config)?;
103+
Ok((cmd.run(client, import_queue), task_manager))
104+
})
105+
},
106+
Some(Subcommand::PurgeChain(cmd)) => {
107+
let runner = cli.create_runner(cmd)?;
108+
runner.sync_run(|config| cmd.run(config.database))
109+
},
110+
Some(Subcommand::Revert(cmd)) => {
111+
let runner = cli.create_runner(cmd)?;
112+
runner.async_run(|config| {
113+
let PartialComponents { client, task_manager, backend, ..}
114+
= new_partial(&config)?;
115+
Ok((cmd.run(client, backend), task_manager))
116+
})
117+
},
78118
None => {
79119
let runner = cli.create_runner(&cli.run)?;
80120
runner.run_node_until_exit(|config| match config.role {

bin/node/cli/src/cli.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ pub struct Cli {
3333
/// Possible subcommands of the main binary.
3434
#[derive(Debug, StructOpt)]
3535
pub enum Subcommand {
36-
/// A set of base subcommands handled by `sc_cli`.
37-
#[structopt(flatten)]
38-
Base(sc_cli::Subcommand),
39-
4036
/// Key management cli utilities
4137
Key(KeySubcommand),
4238

@@ -59,4 +55,25 @@ pub enum Subcommand {
5955

6056
/// Sign a message, with a given (secret) key.
6157
Sign(SignCmd),
58+
59+
/// Build a chain specification.
60+
BuildSpec(sc_cli::BuildSpecCmd),
61+
62+
/// Validate blocks.
63+
CheckBlock(sc_cli::CheckBlockCmd),
64+
65+
/// Export blocks.
66+
ExportBlocks(sc_cli::ExportBlocksCmd),
67+
68+
/// Export the state of a given block into a chain spec.
69+
ExportState(sc_cli::ExportStateCmd),
70+
71+
/// Import blocks.
72+
ImportBlocks(sc_cli::ImportBlocksCmd),
73+
74+
/// Remove the whole chain.
75+
PurgeChain(sc_cli::PurgeChainCmd),
76+
77+
/// Revert the chain to a previous state.
78+
Revert(sc_cli::RevertCmd),
6279
}

bin/node/cli/src/command.rs

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,53 @@ pub fn run() -> Result<()> {
9797
Some(Subcommand::Sign(cmd)) => cmd.run(),
9898
Some(Subcommand::Verify(cmd)) => cmd.run(),
9999
Some(Subcommand::Vanity(cmd)) => cmd.run(),
100-
Some(Subcommand::Base(subcommand)) => {
101-
let runner = cli.create_runner(subcommand)?;
102-
runner.run_subcommand(subcommand, |config| {
103-
let PartialComponents { client, backend, task_manager, import_queue, ..}
100+
Some(Subcommand::BuildSpec(cmd)) => {
101+
let runner = cli.create_runner(cmd)?;
102+
runner.sync_run(|config| cmd.run(config.chain_spec, config.network))
103+
},
104+
Some(Subcommand::CheckBlock(cmd)) => {
105+
let runner = cli.create_runner(cmd)?;
106+
runner.async_run(|config| {
107+
let PartialComponents { client, task_manager, import_queue, ..}
104108
= new_partial(&config)?;
105-
Ok((client, backend, import_queue, task_manager))
109+
Ok((cmd.run(client, import_queue), task_manager))
106110
})
107-
}
111+
},
112+
Some(Subcommand::ExportBlocks(cmd)) => {
113+
let runner = cli.create_runner(cmd)?;
114+
runner.async_run(|config| {
115+
let PartialComponents { client, task_manager, ..}
116+
= new_partial(&config)?;
117+
Ok((cmd.run(client, config.database), task_manager))
118+
})
119+
},
120+
Some(Subcommand::ExportState(cmd)) => {
121+
let runner = cli.create_runner(cmd)?;
122+
runner.async_run(|config| {
123+
let PartialComponents { client, task_manager, ..}
124+
= new_partial(&config)?;
125+
Ok((cmd.run(client, config.chain_spec), task_manager))
126+
})
127+
},
128+
Some(Subcommand::ImportBlocks(cmd)) => {
129+
let runner = cli.create_runner(cmd)?;
130+
runner.async_run(|config| {
131+
let PartialComponents { client, task_manager, import_queue, ..}
132+
= new_partial(&config)?;
133+
Ok((cmd.run(client, import_queue), task_manager))
134+
})
135+
},
136+
Some(Subcommand::PurgeChain(cmd)) => {
137+
let runner = cli.create_runner(cmd)?;
138+
runner.sync_run(|config| cmd.run(config.database))
139+
},
140+
Some(Subcommand::Revert(cmd)) => {
141+
let runner = cli.create_runner(cmd)?;
142+
runner.async_run(|config| {
143+
let PartialComponents { client, task_manager, backend, ..}
144+
= new_partial(&config)?;
145+
Ok((cmd.run(client, backend), task_manager))
146+
})
147+
},
108148
}
109149
}

0 commit comments

Comments
 (0)