1use crate::chain_spec;2use sc_cli;3use std::path::PathBuf;4use structopt::StructOpt;567#[derive(Debug, StructOpt)]8pub enum Subcommand {9 10 #[structopt(name = "export-genesis-state")]11 ExportGenesisState(ExportGenesisStateCommand),1213 14 #[structopt(name = "export-genesis-wasm")]15 ExportGenesisWasm(ExportGenesisWasmCommand),1617 18 BuildSpec(sc_cli::BuildSpecCmd),1920 21 CheckBlock(sc_cli::CheckBlockCmd),2223 24 ExportBlocks(sc_cli::ExportBlocksCmd),2526 27 ExportState(sc_cli::ExportStateCmd),2829 30 ImportBlocks(sc_cli::ImportBlocksCmd),3132 33 PurgeChain(cumulus_client_cli::PurgeChainCmd),3435 36 Revert(sc_cli::RevertCmd),37}383940#[derive(Debug, StructOpt)]41pub struct ExportGenesisStateCommand {42 43 #[structopt(parse(from_os_str))]44 pub output: Option<PathBuf>,4546 47 48 49 #[structopt(long, conflicts_with = "chain")]50 pub parachain_id: Option<u32>,5152 53 #[structopt(short, long)]54 pub raw: bool,5556 57 #[structopt(long, conflicts_with = "parachain-id")]58 pub chain: Option<String>,59}606162#[derive(Debug, StructOpt)]63pub struct ExportGenesisWasmCommand {64 65 #[structopt(parse(from_os_str))]66 pub output: Option<PathBuf>,6768 69 #[structopt(short, long)]70 pub raw: bool,7172 73 #[structopt(long)]74 pub chain: Option<String>,75}7677#[derive(Debug, StructOpt)]78pub struct RunCmd {79 #[structopt(flatten)]80 pub base: sc_cli::RunCmd,8182 83 #[structopt(long)]84 pub parachain_id: Option<u32>,85}8687impl std::ops::Deref for RunCmd {88 type Target = sc_cli::RunCmd;8990 fn deref(&self) -> &Self::Target {91 &self.base92 }93}9495#[derive(Debug, StructOpt)]96#[structopt(settings = &[97 structopt::clap::AppSettings::GlobalVersion,98 structopt::clap::AppSettings::ArgsNegateSubcommands,99 structopt::clap::AppSettings::SubcommandsNegateReqs,100])]101pub struct Cli {102 #[structopt(subcommand)]103 pub subcommand: Option<Subcommand>,104105 #[structopt(flatten)]106 pub run: RunCmd,107108 109 110 111 #[structopt(long, conflicts_with = "validator")]112 pub collator: bool,113114 115 #[structopt(raw = true)]116 pub relaychain_args: Vec<String>,117}118119#[derive(Debug)]120pub struct RelayChainCli {121 122 pub base: polkadot_cli::RunCmd,123124 125 pub chain_id: Option<String>,126127 128 pub base_path: Option<PathBuf>,129}130131impl RelayChainCli {132 133 pub fn new<'a>(134 para_config: &sc_service::Configuration,135 relay_chain_args: impl Iterator<Item = &'a String>,136 ) -> Self {137 let extension = chain_spec::Extensions::try_get(&*para_config.chain_spec);138 let chain_id = extension.map(|e| e.relay_chain.clone());139 let base_path = para_config140 .base_path141 .as_ref()142 .map(|x| x.path().join("polkadot"));143 Self {144 base_path,145 chain_id,146 base: polkadot_cli::RunCmd::from_iter(relay_chain_args),147 }148 }149}