referrerpolicy=no-referrer-when-downgrade

parachain_template_node/
cli.rs

1use polkadot_sdk::*;
2use std::path::PathBuf;
3
4/// Sub-commands supported by the collator.
5#[allow(clippy::large_enum_variant)]
6#[derive(Debug, clap::Subcommand)]
7pub enum Subcommand {
8	/// Build a chain specification.
9	/// DEPRECATED: `build-spec` command will be removed after 1/04/2026. Use `export-chain-spec`
10	/// command instead.
11	#[deprecated(
12		note = "build-spec command will be removed after 1/04/2026. Use export-chain-spec command instead"
13	)]
14	BuildSpec(sc_cli::BuildSpecCmd),
15
16	/// Export the chain specification.
17	ExportChainSpec(sc_cli::ExportChainSpecCmd),
18
19	/// Validate blocks.
20	CheckBlock(sc_cli::CheckBlockCmd),
21
22	/// Export blocks.
23	ExportBlocks(sc_cli::ExportBlocksCmd),
24
25	/// Export the state of a given block into a chain spec.
26	ExportState(sc_cli::ExportStateCmd),
27
28	/// Import blocks.
29	ImportBlocks(sc_cli::ImportBlocksCmd),
30
31	/// Revert the chain to a previous state.
32	Revert(sc_cli::RevertCmd),
33
34	/// Remove the whole chain.
35	PurgeChain(cumulus_client_cli::PurgeChainCmd),
36
37	/// Export the genesis head data of the parachain.
38	///
39	/// Head data is the encoded block header.
40	#[command(alias = "export-genesis-state")]
41	ExportGenesisHead(cumulus_client_cli::ExportGenesisHeadCommand),
42
43	/// Export the genesis wasm of the parachain.
44	ExportGenesisWasm(cumulus_client_cli::ExportGenesisWasmCommand),
45
46	/// Sub-commands concerned with benchmarking.
47	/// The pallet benchmarking moved to the `pallet` sub-command.
48	#[command(subcommand)]
49	Benchmark(frame_benchmarking_cli::BenchmarkCmd),
50}
51
52const AFTER_HELP_EXAMPLE: &str = color_print::cstr!(
53	r#"<bold><underline>Examples:</></>
54   <bold>parachain-template-node build-spec --disable-default-bootnode > plain-parachain-chainspec.json</>
55           Export a chainspec for a local testnet in json format.
56   <bold>parachain-template-node --chain plain-parachain-chainspec.json --tmp -- --chain rococo-local</>
57           Launch a full node with chain specification loaded from plain-parachain-chainspec.json.
58   <bold>parachain-template-node</>
59           Launch a full node with default parachain <italic>local-testnet</> and relay chain <italic>rococo-local</>.
60   <bold>parachain-template-node --collator</>
61           Launch a collator with default parachain <italic>local-testnet</> and relay chain <italic>rococo-local</>.
62 "#
63);
64#[derive(Debug, clap::Parser)]
65#[command(
66	propagate_version = true,
67	args_conflicts_with_subcommands = true,
68	subcommand_negates_reqs = true
69)]
70#[clap(after_help = AFTER_HELP_EXAMPLE)]
71pub struct Cli {
72	#[command(subcommand)]
73	pub subcommand: Option<Subcommand>,
74
75	#[command(flatten)]
76	pub run: cumulus_client_cli::RunCmd,
77
78	/// Disable automatic hardware benchmarks.
79	///
80	/// By default these benchmarks are automatically ran at startup and measure
81	/// the CPU speed, the memory bandwidth and the disk speed.
82	///
83	/// The results are then printed out in the logs, and also sent as part of
84	/// telemetry, if telemetry is enabled.
85	#[arg(long)]
86	pub no_hardware_benchmarks: bool,
87
88	/// Relay chain arguments
89	#[arg(raw = true)]
90	pub relay_chain_args: Vec<String>,
91}
92
93#[derive(Debug)]
94pub struct RelayChainCli {
95	/// The actual relay chain cli object.
96	pub base: polkadot_cli::RunCmd,
97
98	/// Optional chain id that should be passed to the relay chain.
99	pub chain_id: Option<String>,
100
101	/// The base path that should be used by the relay chain.
102	pub base_path: Option<PathBuf>,
103}
104
105impl RelayChainCli {
106	/// Parse the relay chain CLI parameters using the para chain `Configuration`.
107	pub fn new<'a>(
108		para_config: &sc_service::Configuration,
109		relay_chain_args: impl Iterator<Item = &'a String>,
110	) -> Self {
111		let extension = crate::chain_spec::Extensions::try_get(&*para_config.chain_spec);
112		let chain_id = extension.map(|e| e.relay_chain.clone());
113		let base_path = para_config.base_path.path().join("polkadot");
114		Self {
115			base_path: Some(base_path),
116			chain_id,
117			base: clap::Parser::parse_from(relay_chain_args),
118		}
119	}
120}