1use crate::chain_spec;2use std::path::PathBuf;3use clap::Parser;456#[derive(Debug, Parser)]7pub enum Subcommand {8 9 #[clap(name = "export-genesis-state")]10 ExportGenesisState(ExportGenesisStateCommand),1112 13 #[clap(name = "export-genesis-wasm")]14 ExportGenesisWasm(ExportGenesisWasmCommand),1516 17 BuildSpec(sc_cli::BuildSpecCmd),1819 20 CheckBlock(sc_cli::CheckBlockCmd),2122 23 ExportBlocks(sc_cli::ExportBlocksCmd),2425 26 ExportState(sc_cli::ExportStateCmd),2728 29 ImportBlocks(sc_cli::ImportBlocksCmd),3031 32 PurgeChain(cumulus_client_cli::PurgeChainCmd),3334 35 Revert(sc_cli::RevertCmd),3637 38 #[structopt(name = "benchmark", about = "Benchmark runtime pallets.")]39 Benchmark(frame_benchmarking_cli::BenchmarkCmd),40}414243#[derive(Debug, Parser)]44pub struct ExportGenesisStateCommand {45 46 #[clap(parse(from_os_str))]47 pub output: Option<PathBuf>,4849 50 51 52 #[clap(long, conflicts_with = "chain")]53 pub parachain_id: Option<u32>,5455 56 #[clap(short, long)]57 pub raw: bool,5859 60 #[clap(long, conflicts_with = "parachain-id")]61 pub chain: Option<String>,62}636465#[derive(Debug, Parser)]66pub struct ExportGenesisWasmCommand {67 68 #[clap(parse(from_os_str))]69 pub output: Option<PathBuf>,7071 72 #[clap(short, long)]73 pub raw: bool,7475 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 90 #[structopt(raw = true)]91 pub relaychain_args: Vec<String>,92}9394#[derive(Debug)]95pub struct RelayChainCli {96 97 pub base: polkadot_cli::RunCmd,9899 100 pub chain_id: Option<String>,101102 103 pub base_path: Option<PathBuf>,104}105106impl RelayChainCli {107 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}