difftreelog
Use env var as node name
in: master
2 files changed
node/cli/src/cli.rsdiffbeforeafterboth--- a/node/cli/src/cli.rs
+++ b/node/cli/src/cli.rs
@@ -15,9 +15,11 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
use crate::chain_spec;
-use std::path::PathBuf;
+use std::{path::PathBuf, env};
use clap::Parser;
+const NODE_NAME_ENV: &str = "UNIQUE_NODE_NAME";
+
/// Sub-commands supported by the collator.
#[derive(Debug, Parser)]
pub enum Subcommand {
@@ -107,6 +109,12 @@
pub relaychain_args: Vec<String>,
}
+impl Cli {
+ pub fn node_name() -> String {
+ env::var(NODE_NAME_ENV).unwrap_or("Unknown".into())
+ }
+}
+
#[derive(Debug)]
pub struct RelayChainCli {
/// The actual relay chain cli object.
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