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 ExportGenesisState(cumulus_client_cli::ExportGenesisStateCommand),2829 30 ExportGenesisWasm(cumulus_client_cli::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 #[clap(subcommand)]55 Benchmark(frame_benchmarking_cli::BenchmarkCmd),5657 58 TryRuntime(try_runtime_cli::TryRuntimeCmd),59}6061#[derive(Debug, Parser)]62#[clap(args_conflicts_with_subcommands = true, subcommand_negates_reqs = true)]63pub struct Cli {64 #[structopt(subcommand)]65 pub subcommand: Option<Subcommand>,6667 #[structopt(flatten)]68 pub run: cumulus_client_cli::RunCmd,6970 71 72 73 74 75 76 #[structopt(default_value = "500", long)]77 pub idle_autoseal_interval: u64,7879 80 81 82 83 84 85 86 #[clap(long)]87 pub no_hardware_benchmarks: bool,8889 90 #[structopt(raw = true)]91 pub relaychain_args: Vec<String>,92}9394impl Cli {95 pub fn node_name() -> String {96 match env::var(NODE_NAME_ENV).ok() {97 Some(name) => name,98 None => {99 if cfg!(feature = "unique-runtime") {100 "Unique"101 } else if cfg!(feature = "quartz-runtime") {102 "Quartz"103 } else {104 "Opal"105 }106 }107 .into(),108 }109 }110}111112#[derive(Debug)]113pub struct RelayChainCli {114 115 pub base: polkadot_cli::RunCmd,116117 118 pub chain_id: Option<String>,119120 121 pub base_path: Option<PathBuf>,122}123124impl RelayChainCli {125 126 pub fn new<'a>(127 para_config: &sc_service::Configuration,128 relay_chain_args: impl Iterator<Item = &'a String>,129 ) -> Self {130 let extension = chain_spec::Extensions::try_get(&*para_config.chain_spec);131 let chain_id = extension.map(|e| e.relay_chain.clone());132 let base_path = para_config133 .base_path134 .as_ref()135 .map(|x| x.path().join("polkadot"));136 Self {137 base_path,138 chain_id,139 base: polkadot_cli::RunCmd::parse_from(relay_chain_args),140 }141 }142}