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
15// 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/>.
1616
17use crate::chain_spec;17use crate::chain_spec;
18use std::path::PathBuf;18use std::{path::PathBuf, env};
19use clap::Parser;19use clap::Parser;
20
21const NODE_NAME_ENV: &str = "UNIQUE_NODE_NAME";
2022
21/// 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}
111
112impl 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}
109129
110#[derive(Debug)]130#[derive(Debug)]
111pub struct RelayChainCli {131pub struct RelayChainCli {
modifiednode/cli/src/command.rsdiffbeforeafterboth
--- a/node/cli/src/command.rs
+++ b/node/cli/src/command.rs
@@ -99,7 +99,7 @@
 impl SubstrateCli for Cli {
 	// TODO use args
 	fn impl_name() -> String {
-		"Unique Node".into()
+		format!("{} Node", Self::node_name())
 	}
 
 	fn impl_version() -> String {
@@ -108,10 +108,11 @@
 	// TODO use args
 	fn description() -> String {
 		format!(
-			"Unique Node\n\nThe command-line arguments provided first will be \
+			"{} Node\n\nThe command-line arguments provided first will be \
 		passed to the parachain node, while the arguments provided after -- will be passed \
 		to the relaychain node.\n\n\
 		{} [parachain-args] -- [relaychain-args]",
+			Self::node_name(),
 			Self::executable_name()
 		)
 	}
@@ -150,7 +151,7 @@
 impl SubstrateCli for RelayChainCli {
 	// TODO use args
 	fn impl_name() -> String {
-		"Unique Node".into()
+		format!("{} Node", Cli::node_name())
 	}
 
 	fn impl_version() -> String {
@@ -158,11 +159,13 @@
 	}
 	// TODO use args
 	fn description() -> String {
-		"Unique Node\n\nThe command-line arguments provided first will be \
-		passed to the parachain node, while the arguments provided after -- will be passed \
-		to the relaychain node.\n\n\
-		parachain-collator [parachain-args] -- [relaychain-args]"
-			.into()
+		format!(
+			"{} Node\n\nThe command-line arguments provided first will be \
+			passed to the parachain node, while the arguments provided after -- will be passed \
+			to the relaychain node.\n\n\
+			parachain-collator [parachain-args] -- [relaychain-args]",
+			Cli::node_name()
+		)
 	}
 
 	fn author() -> String {