difftreelog
Merge pull request #315 from UniqueNetwork/feature/node-name-env-var
in: master
customize node naming depending on features and env
2 files changed
node/cli/src/cli.rsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617use crate::chain_spec;17use crate::chain_spec;18use std::path::PathBuf;18use std::{path::PathBuf, env};19use clap::Parser;19use clap::Parser;2021const NODE_NAME_ENV: &str = "UNIQUE_NODE_NAME";202221/// Sub-commands supported by the collator.23/// Sub-commands supported by the collator.22#[derive(Debug, Parser)]24#[derive(Debug, Parser)]107 pub relaychain_args: Vec<String>,109 pub relaychain_args: Vec<String>,108}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}109129110#[derive(Debug)]130#[derive(Debug)]111pub struct RelayChainCli {131pub struct RelayChainCli {node/cli/src/command.rsdiffbeforeafterboth99impl SubstrateCli for Cli {99impl SubstrateCli for Cli {100 // TODO use args100 // TODO use args101 fn impl_name() -> String {101 fn impl_name() -> String {102 "Unique Node".into()102 format!("{} Node", Self::node_name())103 }103 }104104105 fn impl_version() -> String {105 fn impl_version() -> String {108 // TODO use args108 // TODO use args109 fn description() -> String {109 fn description() -> String {110 format!(110 format!(111 "Unique Node\n\nThe command-line arguments provided first will be \111 "{} Node\n\nThe command-line arguments provided first will be \112 passed to the parachain node, while the arguments provided after -- will be passed \112 passed to the parachain node, while the arguments provided after -- will be passed \113 to the relaychain node.\n\n\113 to the relaychain node.\n\n\114 {} [parachain-args] -- [relaychain-args]",114 {} [parachain-args] -- [relaychain-args]",115 Self::node_name(),115 Self::executable_name()116 Self::executable_name()116 )117 )117 }118 }150impl SubstrateCli for RelayChainCli {151impl SubstrateCli for RelayChainCli {151 // TODO use args152 // TODO use args152 fn impl_name() -> String {153 fn impl_name() -> String {153 "Unique Node".into()154 format!("{} Node", Cli::node_name())154 }155 }155156156 fn impl_version() -> String {157 fn impl_version() -> String {157 env!("SUBSTRATE_CLI_IMPL_VERSION").into()158 env!("SUBSTRATE_CLI_IMPL_VERSION").into()158 }159 }159 // TODO use args160 // TODO use args160 fn description() -> String {161 fn description() -> String {162 format!(161 "Unique Node\n\nThe command-line arguments provided first will be \163 "{} Node\n\nThe command-line arguments provided first will be \162 passed to the parachain node, while the arguments provided after -- will be passed \164 passed to the parachain node, while the arguments provided after -- will be passed \163 to the relaychain node.\n\n\165 to the relaychain node.\n\n\164 parachain-collator [parachain-args] -- [relaychain-args]"166 parachain-collator [parachain-args] -- [relaychain-args]",165 .into()167 Cli::node_name()168 )166 }169 }167170