git.delta.rocks / unique-network / refs/commits / 744df774aed0

difftreelog

Merge pull request #315 from UniqueNetwork/feature/node-name-env-var

kozyrevdev2022-03-24parents: #c8aac15 #d95afc7.patch.diff
in: master
customize node naming depending on features and env

2 files changed

modifiednode/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,24 @@
 	pub relaychain_args: Vec<String>,
 }
 
+impl Cli {
+	pub fn node_name() -> String {
+		match env::var(NODE_NAME_ENV).ok() {
+			Some(name) => name,
+			None => {
+				if cfg!(feature = "unique-runtime") {
+					"Unique"
+				} else if cfg!(feature = "quartz-runtime") {
+					"Quartz"
+				} else {
+					"Opal"
+				}
+			}
+			.into(),
+		}
+	}
+}
+
 #[derive(Debug)]
 pub struct RelayChainCli {
 	/// The actual relay chain cli object.
modifiednode/cli/src/command.rsdiffbeforeafterboth
99impl SubstrateCli for Cli {99impl SubstrateCli for Cli {
100 // TODO use args100 // TODO use args
101 fn impl_name() -> String {101 fn impl_name() -> String {
102 "Unique Node".into()102 format!("{} Node", Self::node_name())
103 }103 }
104104
105 fn impl_version() -> String {105 fn impl_version() -> String {
108 // TODO use args108 // TODO use args
109 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 args
152 fn impl_name() -> String {153 fn impl_name() -> String {
153 "Unique Node".into()154 format!("{} Node", Cli::node_name())
154 }155 }
155156
156 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 args
160 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