1234567891011121314151617use crate::chain_spec;18use std::path::PathBuf;19use clap::Parser;202122#[derive(Debug, Parser)]23pub enum Subcommand {24 25 #[clap(name = "export-genesis-state")]26 ExportGenesisState(ExportGenesisStateCommand),2728 29 #[clap(name = "export-genesis-wasm")]30 ExportGenesisWasm(ExportGenesisWasmCommand),3132 33 BuildSpec(sc_cli::BuildSpecCmd),3435 36 CheckBlock(sc_cli::CheckBlockCmd),3738 39 ExportBlocks(sc_cli::ExportBlocksCmd),4041 42 ExportState(sc_cli::ExportStateCmd),4344 45 ImportBlocks(sc_cli::ImportBlocksCmd),4647 48 PurgeChain(cumulus_client_cli::PurgeChainCmd),4950 51 Revert(sc_cli::RevertCmd),5253 54 #[structopt(name = "benchmark", about = "Benchmark runtime pallets.")]55 Benchmark(frame_benchmarking_cli::BenchmarkCmd),56}575859#[derive(Debug, Parser)]60pub struct ExportGenesisStateCommand {61 62 #[clap(parse(from_os_str))]63 pub output: Option<PathBuf>,6465 66 67 68 #[clap(long, conflicts_with = "chain")]69 pub parachain_id: Option<u32>,7071 72 #[clap(short, long)]73 pub raw: bool,7475 76 #[clap(long, conflicts_with = "parachain-id")]77 pub chain: Option<String>,78}798081#[derive(Debug, Parser)]82pub struct ExportGenesisWasmCommand {83 84 #[clap(parse(from_os_str))]85 pub output: Option<PathBuf>,8687 88 #[clap(short, long)]89 pub raw: bool,9091 92 #[clap(long)]93 pub chain: Option<String>,94}9596#[derive(Debug, Parser)]97#[clap(args_conflicts_with_subcommands = true, subcommand_negates_reqs = true)]98pub struct Cli {99 #[structopt(subcommand)]100 pub subcommand: Option<Subcommand>,101102 #[structopt(flatten)]103 pub run: cumulus_client_cli::RunCmd,104105 106 #[structopt(raw = true)]107 pub relaychain_args: Vec<String>,108}109110#[derive(Debug)]111pub struct RelayChainCli {112 113 pub base: polkadot_cli::RunCmd,114115 116 pub chain_id: Option<String>,117118 119 pub base_path: Option<PathBuf>,120}121122impl RelayChainCli {123 124 pub fn new<'a>(125 para_config: &sc_service::Configuration,126 relay_chain_args: impl Iterator<Item = &'a String>,127 ) -> Self {128 let extension = chain_spec::Extensions::try_get(&*para_config.chain_spec);129 let chain_id = extension.map(|e| e.relay_chain.clone());130 let base_path = para_config131 .base_path132 .as_ref()133 .map(|x| x.path().join("polkadot"));134 Self {135 base_path,136 chain_id,137 base: polkadot_cli::RunCmd::parse_from(relay_chain_args),138 }139 }140}