git.delta.rocks / unique-network / refs/commits / f31314788bb5

difftreelog

source

node/cli/src/cli.rs3.3 KiBsourcehistory
1use crate::chain_spec;2use std::path::PathBuf;3use clap::Parser;45/// Sub-commands supported by the collator.6#[derive(Debug, Parser)]7pub enum Subcommand {8	/// Export the genesis state of the parachain.9	#[clap(name = "export-genesis-state")]10	ExportGenesisState(ExportGenesisStateCommand),1112	/// Export the genesis wasm of the parachain.13	#[clap(name = "export-genesis-wasm")]14	ExportGenesisWasm(ExportGenesisWasmCommand),1516	/// Build a chain specification.17	BuildSpec(sc_cli::BuildSpecCmd),1819	/// Validate blocks.20	CheckBlock(sc_cli::CheckBlockCmd),2122	/// Export blocks.23	ExportBlocks(sc_cli::ExportBlocksCmd),2425	/// Export the state of a given block into a chain spec.26	ExportState(sc_cli::ExportStateCmd),2728	/// Import blocks.29	ImportBlocks(sc_cli::ImportBlocksCmd),3031	/// Remove the whole chain.32	PurgeChain(cumulus_client_cli::PurgeChainCmd),3334	/// Revert the chain to a previous state.35	Revert(sc_cli::RevertCmd),3637	/// The custom benchmark subcommmand benchmarking runtime pallets.38	#[structopt(name = "benchmark", about = "Benchmark runtime pallets.")]39	Benchmark(frame_benchmarking_cli::BenchmarkCmd),40}4142/// Command for exporting the genesis state of the parachain43#[derive(Debug, Parser)]44pub struct ExportGenesisStateCommand {45	/// Output file name or stdout if unspecified.46	#[clap(parse(from_os_str))]47	pub output: Option<PathBuf>,4849	/// Id of the parachain this state is for.50	///51	/// Default: 10052	#[clap(long, conflicts_with = "chain")]53	pub parachain_id: Option<u32>,5455	/// Write output in binary. Default is to write in hex.56	#[clap(short, long)]57	pub raw: bool,5859	/// The name of the chain for that the genesis state should be exported.60	#[clap(long, conflicts_with = "parachain-id")]61	pub chain: Option<String>,62}6364/// Command for exporting the genesis wasm file.65#[derive(Debug, Parser)]66pub struct ExportGenesisWasmCommand {67	/// Output file name or stdout if unspecified.68	#[clap(parse(from_os_str))]69	pub output: Option<PathBuf>,7071	/// Write output in binary. Default is to write in hex.72	#[clap(short, long)]73	pub raw: bool,7475	/// The name of the chain for that the genesis wasm file should be exported.76	#[clap(long)]77	pub chain: Option<String>,78}7980#[derive(Debug, Parser)]81#[clap(args_conflicts_with_subcommands = true, subcommand_negates_reqs = true)]82pub struct Cli {83	#[structopt(subcommand)]84	pub subcommand: Option<Subcommand>,8586	#[structopt(flatten)]87	pub run: cumulus_client_cli::RunCmd,8889	/// Relaychain arguments90	#[structopt(raw = true)]91	pub relaychain_args: Vec<String>,92}9394#[derive(Debug)]95pub struct RelayChainCli {96	/// The actual relay chain cli object.97	pub base: polkadot_cli::RunCmd,9899	/// Optional chain id that should be passed to the relay chain.100	pub chain_id: Option<String>,101102	/// The base path that should be used by the relay chain.103	pub base_path: Option<PathBuf>,104}105106impl RelayChainCli {107	/// Parse the relay chain CLI parameters using the para chain `Configuration`.108	pub fn new<'a>(109		para_config: &sc_service::Configuration,110		relay_chain_args: impl Iterator<Item = &'a String>,111	) -> Self {112		let extension = chain_spec::Extensions::try_get(&*para_config.chain_spec);113		let chain_id = extension.map(|e| e.relay_chain.clone());114		let base_path = para_config115			.base_path116			.as_ref()117			.map(|x| x.path().join("polkadot"));118		Self {119			base_path,120			chain_id,121			base: polkadot_cli::RunCmd::parse_from(relay_chain_args),122		}123	}124}