From 21bc247cd03f6d6a785ea1fd8a26ab39f7258945 Mon Sep 17 00:00:00 2001
From: Seemant Aggarwal <seemant.aggarwal@parity.io>
Date: Sat, 8 Mar 2025 13:17:13 +0530
Subject: [PATCH] addressing comments and fixes

---
 polkadot/cli/src/cli.rs                       |  1 +
 polkadot/cli/src/command.rs                   |  5 +++--
 substrate/bin/node/cli/src/cli.rs             |  5 +++--
 substrate/bin/node/cli/src/command.rs         |  5 +++--
 .../cli/src/commands/export_chain_spec_cmd.rs | 21 ++++++++++++++-----
 templates/minimal/node/src/cli.rs             | 10 ++++-----
 templates/minimal/node/src/command.rs         |  5 +++--
 templates/parachain/node/src/cli.rs           |  5 +++--
 templates/parachain/node/src/command.rs       |  6 +++---
 templates/solochain/node/src/cli.rs           |  7 +++----
 templates/solochain/node/src/command.rs       |  5 +++--
 11 files changed, 45 insertions(+), 30 deletions(-)

diff --git a/polkadot/cli/src/cli.rs b/polkadot/cli/src/cli.rs
index bc5b80f9a94..3b3600dc38f 100644
--- a/polkadot/cli/src/cli.rs
+++ b/polkadot/cli/src/cli.rs
@@ -25,6 +25,7 @@ use std::path::PathBuf;
 #[derive(Debug, Parser)]
 pub enum Subcommand {
 	/// Build a chain specification.
+	#[deprecated(note = "build-spec will be removed after 1/04/2026. Use export-chain-spec instead")]
 	BuildSpec(sc_cli::BuildSpecCmd),
 
 	/// Export the chain specification.
diff --git a/polkadot/cli/src/command.rs b/polkadot/cli/src/command.rs
index abecdc0bc09..cb7a35f1e53 100644
--- a/polkadot/cli/src/command.rs
+++ b/polkadot/cli/src/command.rs
@@ -287,14 +287,15 @@ pub fn run() -> Result<()> {
 			None,
 			polkadot_node_metrics::logger_hook(),
 		),
+		#[allow(deprecated)]
 		Some(Subcommand::BuildSpec(cmd)) => {
 			let runner = cli.create_runner(cmd)?;
 			Ok(runner.sync_run(|config| cmd.run(config.chain_spec, config.network))?)
 		},
 		Some(Subcommand::ExportChainSpec(cmd)) => {
 			// Directly load the embedded chain spec using the CLI’s load_spec method.
-			let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?;
-			cmd.run(spec).map_err(Into::into)
+			let runner = cli.create_runner(cmd)?;
+			Ok(runner.sync_run(|config| cmd.run(config.chain_spec))?)
 		},
 		Some(Subcommand::CheckBlock(cmd)) => {
 			let runner = cli.create_runner(cmd).map_err(Error::SubstrateCli)?;
diff --git a/substrate/bin/node/cli/src/cli.rs b/substrate/bin/node/cli/src/cli.rs
index 0403779cde8..098b3d5cccc 100644
--- a/substrate/bin/node/cli/src/cli.rs
+++ b/substrate/bin/node/cli/src/cli.rs
@@ -16,7 +16,7 @@
 // You should have received a copy of the GNU General Public License
 // along with this program. If not, see <https://www.gnu.org/licenses/>.
 
-use polkadot_sdk::{sc_cli::ExportChainSpecCmd, *};
+use polkadot_sdk::*;
 
 /// An overarching CLI command definition.
 #[derive(Debug, clap::Parser)]
@@ -78,10 +78,11 @@ pub enum Subcommand {
 	Sign(sc_cli::SignCmd),
 
 	/// Build a chain specification.
+	#[deprecated(note = "build-spec will be removed after 1/04/2026. Use export-chain-spec instead")]
 	BuildSpec(sc_cli::BuildSpecCmd),
 
 	/// Export the chain specification.
-	ExportChainSpec(ExportChainSpecCmd),
+	ExportChainSpec(sc_cli::ExportChainSpecCmd),
 
 	/// Validate blocks.
 	CheckBlock(sc_cli::CheckBlockCmd),
diff --git a/substrate/bin/node/cli/src/command.rs b/substrate/bin/node/cli/src/command.rs
index c55f9deae86..16a8ffa5ebf 100644
--- a/substrate/bin/node/cli/src/command.rs
+++ b/substrate/bin/node/cli/src/command.rs
@@ -95,8 +95,8 @@ pub fn run() -> Result<()> {
 		},
 		Some(Subcommand::ExportChainSpec(cmd)) => {
 			// Directly load the embedded chain spec using the CLI’s load_spec method.
-			let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?;
-			cmd.run(spec)
+			let runner = cli.create_runner(cmd)?;
+			Ok(runner.sync_run(|config| cmd.run(config.chain_spec))?)
 		},
 		Some(Subcommand::Benchmark(cmd)) => {
 			let runner = cli.create_runner(cmd)?;
@@ -178,6 +178,7 @@ pub fn run() -> Result<()> {
 		Some(Subcommand::Sign(cmd)) => cmd.run(),
 		Some(Subcommand::Verify(cmd)) => cmd.run(),
 		Some(Subcommand::Vanity(cmd)) => cmd.run(),
+		#[allow(deprecated)]
 		Some(Subcommand::BuildSpec(cmd)) => {
 			let runner = cli.create_runner(cmd)?;
 			runner.sync_run(|config| cmd.run(config.chain_spec, config.network))
diff --git a/substrate/client/cli/src/commands/export_chain_spec_cmd.rs b/substrate/client/cli/src/commands/export_chain_spec_cmd.rs
index c865ead3e7f..5537c3f0791 100644
--- a/substrate/client/cli/src/commands/export_chain_spec_cmd.rs
+++ b/substrate/client/cli/src/commands/export_chain_spec_cmd.rs
@@ -23,8 +23,8 @@ use std::{
 	io::{self, Write},
 	path::PathBuf,
 };
-
-use crate::{error::Result, SharedParams};
+use std::thread::sleep;
+use crate::{error::Result, BuildSpecCmd, CliConfiguration, NodeKeyParams, SharedParams};
 
 /// Export a chain-spec to a JSON file in plain or in raw storage format.
 ///
@@ -42,9 +42,8 @@ use crate::{error::Result, SharedParams};
 #[derive(Debug, Clone, Parser)]
 pub struct ExportChainSpecCmd {
 	/// The chain spec identifier to export.
-	#[allow(missing_docs)]
-	#[clap(flatten)]
-	pub shared_params: SharedParams,
+	#[arg(long, default_value = "local")]
+	pub chain: String,
 
 	/// `chain-spec` JSON file path. If omitted, prints to stdout.
 	#[arg(long)]
@@ -69,3 +68,15 @@ impl ExportChainSpecCmd {
 		Ok(())
 	}
 }
+impl CliConfiguration for ExportChainSpecCmd {
+
+	// If ExportChainSpecCmd doesn’t have shared_params, you must provide some implementation.
+	fn shared_params(&self) -> &SharedParams {
+		unimplemented!("ExportChainSpecCmd does not implement shared_params")
+	}
+
+	// Implement the chain_id method to return the chain identifier.
+	fn chain_id(&self, _is_dev: bool) -> Result<String> {
+		Ok(self.chain.clone())
+	}
+}
diff --git a/templates/minimal/node/src/cli.rs b/templates/minimal/node/src/cli.rs
index 8ddd7d4fd25..c07e74acc04 100644
--- a/templates/minimal/node/src/cli.rs
+++ b/templates/minimal/node/src/cli.rs
@@ -15,10 +15,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-use polkadot_sdk::{
-	sc_cli::{ExportChainSpecCmd, RunCmd},
-	*,
-};
+use polkadot_sdk::*;
 
 #[derive(Debug, Clone)]
 pub enum Consensus {
@@ -52,7 +49,7 @@ pub struct Cli {
 	pub consensus: Consensus,
 
 	#[clap(flatten)]
-	pub run: RunCmd,
+	pub run: sc_cli::RunCmd,
 }
 
 #[derive(Debug, clap::Subcommand)]
@@ -62,10 +59,11 @@ pub enum Subcommand {
 	Key(sc_cli::KeySubcommand),
 
 	/// Build a chain specification.
+	#[deprecated(note = "build-spec will be removed after 1/04/2026. Use export-chain-spec instead")]
 	BuildSpec(sc_cli::BuildSpecCmd),
 
 	/// Export the chain specification.
-	ExportChainSpec(ExportChainSpecCmd),
+	ExportChainSpec(sc_cli::ExportChainSpecCmd),
 
 	/// Validate blocks.
 	CheckBlock(sc_cli::CheckBlockCmd),
diff --git a/templates/minimal/node/src/command.rs b/templates/minimal/node/src/command.rs
index ea5684b5f7d..5b221272dc1 100644
--- a/templates/minimal/node/src/command.rs
+++ b/templates/minimal/node/src/command.rs
@@ -62,6 +62,7 @@ pub fn run() -> sc_cli::Result<()> {
 
 	match &cli.subcommand {
 		Some(Subcommand::Key(cmd)) => cmd.run(&cli),
+		#[allow(deprecated)]
 		Some(Subcommand::BuildSpec(cmd)) => {
 			let runner = cli.create_runner(cmd)?;
 			runner.sync_run(|config| cmd.run(config.chain_spec, config.network))
@@ -76,8 +77,8 @@ pub fn run() -> sc_cli::Result<()> {
 		},
 		Some(Subcommand::ExportChainSpec(cmd)) => {
 			// Directly load the embedded chain spec using the CLI’s load_spec method.
-			let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?;
-			cmd.run(&*spec)
+			let runner = cli.create_runner(cmd)?;
+			Ok(runner.sync_run(|config| cmd.run(config.chain_spec))?)
 		},
 		Some(Subcommand::ExportBlocks(cmd)) => {
 			let runner = cli.create_runner(cmd)?;
diff --git a/templates/parachain/node/src/cli.rs b/templates/parachain/node/src/cli.rs
index dcd43164607..d0ce9136414 100644
--- a/templates/parachain/node/src/cli.rs
+++ b/templates/parachain/node/src/cli.rs
@@ -1,4 +1,4 @@
-use polkadot_sdk::{sc_cli::ExportChainSpecCmd, *};
+use polkadot_sdk::*;
 use std::path::PathBuf;
 
 /// Sub-commands supported by the collator.
@@ -6,10 +6,11 @@ use std::path::PathBuf;
 #[derive(Debug, clap::Subcommand)]
 pub enum Subcommand {
 	/// Build a chain specification.
+	#[deprecated(note = "build-spec will be removed after 1/04/2026. Use export-chain-spec instead")]
 	BuildSpec(sc_cli::BuildSpecCmd),
 
 	/// Export the chain specification.
-	ExportChainSpec(ExportChainSpecCmd),
+	ExportChainSpec(sc_cli::ExportChainSpecCmd),
 
 	/// Validate blocks.
 	CheckBlock(sc_cli::CheckBlockCmd),
diff --git a/templates/parachain/node/src/command.rs b/templates/parachain/node/src/command.rs
index 983d9ecd004..eec37292c29 100644
--- a/templates/parachain/node/src/command.rs
+++ b/templates/parachain/node/src/command.rs
@@ -114,6 +114,7 @@ pub fn run() -> Result<()> {
 	let cli = Cli::from_args();
 
 	match &cli.subcommand {
+		#[allow(deprecated)]
 		Some(Subcommand::BuildSpec(cmd)) => {
 			let runner = cli.create_runner(cmd)?;
 			runner.sync_run(|config| cmd.run(config.chain_spec, config.network))
@@ -124,9 +125,8 @@ pub fn run() -> Result<()> {
 			})
 		},
 		Some(Subcommand::ExportChainSpec(cmd)) => {
-			// Directly load the embedded chain spec using the CLI’s load_spec method.
-			let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?;
-			cmd.run(&*spec)
+			let runner = cli.create_runner(cmd)?;
+			Ok(runner.sync_run(|config| cmd.run(config.chain_spec))?)
 		},
 		Some(Subcommand::ExportBlocks(cmd)) => {
 			construct_async_run!(|components, cli, cmd, config| {
diff --git a/templates/solochain/node/src/cli.rs b/templates/solochain/node/src/cli.rs
index ba5dc2caf62..d7edc2850fe 100644
--- a/templates/solochain/node/src/cli.rs
+++ b/templates/solochain/node/src/cli.rs
@@ -1,12 +1,10 @@
-use sc_cli::{ExportChainSpecCmd, RunCmd};
-
 #[derive(Debug, clap::Parser)]
 pub struct Cli {
 	#[command(subcommand)]
 	pub subcommand: Option<Subcommand>,
 
 	#[clap(flatten)]
-	pub run: RunCmd,
+	pub run: sc_cli::RunCmd,
 }
 
 #[derive(Debug, clap::Subcommand)]
@@ -17,10 +15,11 @@ pub enum Subcommand {
 	Key(sc_cli::KeySubcommand),
 
 	/// Build a chain specification.
+	#[deprecated(note = "build-spec will be removed after 1/04/2026. Use export-chain-spec instead")]
 	BuildSpec(sc_cli::BuildSpecCmd),
 
 	/// Export the chain specification.
-	ExportChainSpec(ExportChainSpecCmd),
+	ExportChainSpec(sc_cli::ExportChainSpecCmd),
 
 	/// Validate blocks.
 	CheckBlock(sc_cli::CheckBlockCmd),
diff --git a/templates/solochain/node/src/command.rs b/templates/solochain/node/src/command.rs
index 5d7cd61a90d..6520c862480 100644
--- a/templates/solochain/node/src/command.rs
+++ b/templates/solochain/node/src/command.rs
@@ -51,6 +51,7 @@ pub fn run() -> sc_cli::Result<()> {
 
 	match &cli.subcommand {
 		Some(Subcommand::Key(cmd)) => cmd.run(&cli),
+		#[allow(deprecated)]
 		Some(Subcommand::BuildSpec(cmd)) => {
 			let runner = cli.create_runner(cmd)?;
 			runner.sync_run(|config| cmd.run(config.chain_spec, config.network))
@@ -65,8 +66,8 @@ pub fn run() -> sc_cli::Result<()> {
 		},
 		Some(Subcommand::ExportChainSpec(cmd)) => {
 			// Directly load the embedded chain spec using the CLI’s load_spec method.
-			let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?;
-			cmd.run(&*spec)
+			let runner = cli.create_runner(cmd)?;
+			Ok(runner.sync_run(|config| cmd.run(config.chain_spec))?)
 		},
 		Some(Subcommand::ExportBlocks(cmd)) => {
 			let runner = cli.create_runner(cmd)?;
-- 
GitLab