difftreelog
Use different default node name according to enabled feature
in: master
1 file changed
node/cli/src/cli.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use crate::chain_spec;18use std::{path::PathBuf, env};19use clap::Parser;2021const NODE_NAME_ENV: &str = "UNIQUE_NODE_NAME";2223/// Sub-commands supported by the collator.24#[derive(Debug, Parser)]25pub enum Subcommand {26 /// Export the genesis state of the parachain.27 #[clap(name = "export-genesis-state")]28 ExportGenesisState(ExportGenesisStateCommand),2930 /// Export the genesis wasm of the parachain.31 #[clap(name = "export-genesis-wasm")]32 ExportGenesisWasm(ExportGenesisWasmCommand),3334 /// Build a chain specification.35 BuildSpec(sc_cli::BuildSpecCmd),3637 /// Validate blocks.38 CheckBlock(sc_cli::CheckBlockCmd),3940 /// Export blocks.41 ExportBlocks(sc_cli::ExportBlocksCmd),4243 /// Export the state of a given block into a chain spec.44 ExportState(sc_cli::ExportStateCmd),4546 /// Import blocks.47 ImportBlocks(sc_cli::ImportBlocksCmd),4849 /// Remove the whole chain.50 PurgeChain(cumulus_client_cli::PurgeChainCmd),5152 /// Revert the chain to a previous state.53 Revert(sc_cli::RevertCmd),5455 /// The custom benchmark subcommmand benchmarking runtime pallets.56 #[structopt(name = "benchmark", about = "Benchmark runtime pallets.")]57 Benchmark(frame_benchmarking_cli::BenchmarkCmd),58}5960/// Command for exporting the genesis state of the parachain61#[derive(Debug, Parser)]62pub struct ExportGenesisStateCommand {63 /// Output file name or stdout if unspecified.64 #[clap(parse(from_os_str))]65 pub output: Option<PathBuf>,6667 /// Id of the parachain this state is for.68 ///69 /// Default: 10070 #[clap(long, conflicts_with = "chain")]71 pub parachain_id: Option<u32>,7273 /// Write output in binary. Default is to write in hex.74 #[clap(short, long)]75 pub raw: bool,7677 /// The name of the chain for that the genesis state should be exported.78 #[clap(long, conflicts_with = "parachain-id")]79 pub chain: Option<String>,80}8182/// Command for exporting the genesis wasm file.83#[derive(Debug, Parser)]84pub struct ExportGenesisWasmCommand {85 /// Output file name or stdout if unspecified.86 #[clap(parse(from_os_str))]87 pub output: Option<PathBuf>,8889 /// Write output in binary. Default is to write in hex.90 #[clap(short, long)]91 pub raw: bool,9293 /// The name of the chain for that the genesis wasm file should be exported.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 /// Relaychain arguments108 #[structopt(raw = true)]109 pub relaychain_args: Vec<String>,110}111112impl Cli {113 pub fn node_name() -> String {114 env::var(NODE_NAME_ENV).unwrap_or("Unknown".into())115 }116}117118#[derive(Debug)]119pub struct RelayChainCli {120 /// The actual relay chain cli object.121 pub base: polkadot_cli::RunCmd,122123 /// Optional chain id that should be passed to the relay chain.124 pub chain_id: Option<String>,125126 /// The base path that should be used by the relay chain.127 pub base_path: Option<PathBuf>,128}129130impl RelayChainCli {131 /// Parse the relay chain CLI parameters using the para chain `Configuration`.132 pub fn new<'a>(133 para_config: &sc_service::Configuration,134 relay_chain_args: impl Iterator<Item = &'a String>,135 ) -> Self {136 let extension = chain_spec::Extensions::try_get(&*para_config.chain_spec);137 let chain_id = extension.map(|e| e.relay_chain.clone());138 let base_path = para_config139 .base_path140 .as_ref()141 .map(|x| x.path().join("polkadot"));142 Self {143 base_path,144 chain_id,145 base: polkadot_cli::RunCmd::parse_from(relay_chain_args),146 }147 }148}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use crate::chain_spec;18use std::{path::PathBuf, env};19use clap::Parser;2021const NODE_NAME_ENV: &str = "UNIQUE_NODE_NAME";2223/// Sub-commands supported by the collator.24#[derive(Debug, Parser)]25pub enum Subcommand {26 /// Export the genesis state of the parachain.27 #[clap(name = "export-genesis-state")]28 ExportGenesisState(ExportGenesisStateCommand),2930 /// Export the genesis wasm of the parachain.31 #[clap(name = "export-genesis-wasm")]32 ExportGenesisWasm(ExportGenesisWasmCommand),3334 /// Build a chain specification.35 BuildSpec(sc_cli::BuildSpecCmd),3637 /// Validate blocks.38 CheckBlock(sc_cli::CheckBlockCmd),3940 /// Export blocks.41 ExportBlocks(sc_cli::ExportBlocksCmd),4243 /// Export the state of a given block into a chain spec.44 ExportState(sc_cli::ExportStateCmd),4546 /// Import blocks.47 ImportBlocks(sc_cli::ImportBlocksCmd),4849 /// Remove the whole chain.50 PurgeChain(cumulus_client_cli::PurgeChainCmd),5152 /// Revert the chain to a previous state.53 Revert(sc_cli::RevertCmd),5455 /// The custom benchmark subcommmand benchmarking runtime pallets.56 #[structopt(name = "benchmark", about = "Benchmark runtime pallets.")]57 Benchmark(frame_benchmarking_cli::BenchmarkCmd),58}5960/// Command for exporting the genesis state of the parachain61#[derive(Debug, Parser)]62pub struct ExportGenesisStateCommand {63 /// Output file name or stdout if unspecified.64 #[clap(parse(from_os_str))]65 pub output: Option<PathBuf>,6667 /// Id of the parachain this state is for.68 ///69 /// Default: 10070 #[clap(long, conflicts_with = "chain")]71 pub parachain_id: Option<u32>,7273 /// Write output in binary. Default is to write in hex.74 #[clap(short, long)]75 pub raw: bool,7677 /// The name of the chain for that the genesis state should be exported.78 #[clap(long, conflicts_with = "parachain-id")]79 pub chain: Option<String>,80}8182/// Command for exporting the genesis wasm file.83#[derive(Debug, Parser)]84pub struct ExportGenesisWasmCommand {85 /// Output file name or stdout if unspecified.86 #[clap(parse(from_os_str))]87 pub output: Option<PathBuf>,8889 /// Write output in binary. Default is to write in hex.90 #[clap(short, long)]91 pub raw: bool,9293 /// The name of the chain for that the genesis wasm file should be exported.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 /// Relaychain arguments108 #[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 /// The actual relay chain cli object.133 pub base: polkadot_cli::RunCmd,134135 /// Optional chain id that should be passed to the relay chain.136 pub chain_id: Option<String>,137138 /// The base path that should be used by the relay chain.139 pub base_path: Option<PathBuf>,140}141142impl RelayChainCli {143 /// Parse the relay chain CLI parameters using the para chain `Configuration`.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}