1234567891011121314151617use crate::chain_spec;18use std::{path::PathBuf, env};19use clap::Parser;2021const NODE_NAME_ENV: &str = "UNIQUE_NODE_NAME";222324#[derive(Debug, Parser)]25pub enum Subcommand {26 27 #[clap(name = "export-genesis-state")]28 ExportGenesisState(ExportGenesisStateCommand),2930 31 #[clap(name = "export-genesis-wasm")]32 ExportGenesisWasm(ExportGenesisWasmCommand),3334 35 BuildSpec(sc_cli::BuildSpecCmd),3637 38 CheckBlock(sc_cli::CheckBlockCmd),3940 41 ExportBlocks(sc_cli::ExportBlocksCmd),4243 44 ExportState(sc_cli::ExportStateCmd),4546 47 ImportBlocks(sc_cli::ImportBlocksCmd),4849 50 PurgeChain(cumulus_client_cli::PurgeChainCmd),5152 53 Revert(sc_cli::RevertCmd),5455 56 #[structopt(name = "benchmark", about = "Benchmark runtime pallets.")]57 Benchmark(frame_benchmarking_cli::BenchmarkCmd),58}596061#[derive(Debug, Parser)]62pub struct ExportGenesisStateCommand {63 64 #[clap(parse(from_os_str))]65 pub output: Option<PathBuf>,6667 68 69 70 #[clap(long, conflicts_with = "chain")]71 pub parachain_id: Option<u32>,7273 74 #[clap(short, long)]75 pub raw: bool,7677 78 #[clap(long, conflicts_with = "parachain-id")]79 pub chain: Option<String>,80}818283#[derive(Debug, Parser)]84pub struct ExportGenesisWasmCommand {85 86 #[clap(parse(from_os_str))]87 pub output: Option<PathBuf>,8889 90 #[clap(short, long)]91 pub raw: bool,9293 94 #[clap(long)]95 pub chain: Option<String>,96}9798#[derive(Debug, Parser)]99#[clap(args_conflicts_with_subcommands = true, subcommand_negates_reqs = true)]100pub struct Cli {101 #[structopt(subcommand)]102 pub subcommand: Option<Subcommand>,103104 #[structopt(flatten)]105 pub run: cumulus_client_cli::RunCmd,106107 108 #[structopt(raw = true)]109 pub relaychain_args: Vec<String>,110}111112impl Cli {113 pub fn node_name() -> String {114 match env::var(NODE_NAME_ENV).ok() {115 Some(name) => name,116 None => {117 if cfg!(feature = "unique-runtime") {118 "Unique"119 } else if cfg!(feature = "quartz-runtime") {120 "Quartz"121 } else {122 "Opal"123 }124 }125 .into(),126 }127 }128}129130#[derive(Debug)]131pub struct RelayChainCli {132 133 pub base: polkadot_cli::RunCmd,134135 136 pub chain_id: Option<String>,137138 139 pub base_path: Option<PathBuf>,140}141142impl RelayChainCli {143 144 pub fn new<'a>(145 para_config: &sc_service::Configuration,146 relay_chain_args: impl Iterator<Item = &'a String>,147 ) -> Self {148 let extension = chain_spec::Extensions::try_get(&*para_config.chain_spec);149 let chain_id = extension.map(|e| e.relay_chain.clone());150 let base_path = para_config151 .base_path152 .as_ref()153 .map(|x| x.path().join("polkadot"));154 Self {155 base_path,156 chain_id,157 base: polkadot_cli::RunCmd::parse_from(relay_chain_args),158 }159 }160}