Skip to content

Commit

Permalink
multi runtime development node cli
Browse files Browse the repository at this point in the history
  • Loading branch information
smohan-dw committed Jun 10, 2024
1 parent 825e62d commit 25db2e8
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 12 deletions.
26 changes: 18 additions & 8 deletions node/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,24 @@ pub enum Subcommand {

/// Db meta columns information.
ChainInfo(sc_cli::ChainInfoCmd),

/// Start Braid development node
Braid {
#[clap(long = "dev", required = true, help = "Run the Braid node in development mode")]
dev: bool,
},

/// Start Loom development node
Loom {
#[clap(long = "dev", required = true, help = "Run the Loom node in development mode")]
dev: bool,
},

/// Start Weave development node
Weave {
#[clap(long = "dev", required = true, help = "Run the Weave node in development mode")]
dev: bool,
},
}

#[allow(missing_docs)]
Expand All @@ -90,14 +108,6 @@ pub struct Cli {
#[clap(flatten)]
pub run: sc_cli::RunCmd,

/// Force using Braid runtime.
#[arg(long = "force-braid")]
pub force_braid: bool,

/// Force using Loom runtime.
#[arg(long = "force-loom")]
pub force_loom: bool,

#[arg(long)]
pub no_hardware_benchmarks: bool,

Expand Down
52 changes: 48 additions & 4 deletions node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,20 @@ impl SubstrateCli for Cli {
}

fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
let incoming_id = id;

let id = if id == "" {
let n = get_exec_name().unwrap_or_default();
["cord", "braid", "loom", "weave"]
["braid", "loom", "weave"]
.iter()
.cloned()
.find(|&chain| n.starts_with(chain))
.unwrap_or("braid")
} else {
id
match id {
"braid_dev_node" | "loom_dev_node" | "weave_dev_node" => "dev",
_ => id,
}
};
Ok(match id {
#[cfg(feature = "braid-native")]
Expand All @@ -93,7 +98,13 @@ impl SubstrateCli for Cli {
#[cfg(feature = "weave-native")]
"weave" => Box::new(chain_spec::weave_development_config()?),
#[cfg(feature = "braid-native")]
"dev" | "braid-dev" => Box::new(chain_spec::braid_development_config()?),
"dev" | "cord" => match incoming_id {
"braid_dev_node" => Box::new(chain_spec::braid_development_config()?),
"loom_dev_node" => Box::new(chain_spec::loom_development_config()?),
"weave_dev_node" => Box::new(chain_spec::weave_development_config()?),
_ => Box::new(chain_spec::braid_development_config()?),
},
"braid-dev" => Box::new(chain_spec::braid_development_config()?),
#[cfg(feature = "loom-native")]
"loom-dev" => Box::new(chain_spec::loom_development_config()?),
#[cfg(feature = "weave-native")]
Expand Down Expand Up @@ -154,7 +165,7 @@ fn set_default_ss58_version(spec: &Box<dyn cord_service::ChainSpec>) {

/// Parse command line arguments into service configuration.
pub fn run() -> Result<()> {
let cli: Cli = Cli::from_args();
let mut cli: Cli = Cli::from_args();

match &cli.subcommand {
None => {
Expand All @@ -165,6 +176,39 @@ pub fn run() -> Result<()> {
cord_service::new_full(config, cli).map_err(sc_cli::Error::Service)
})
},
Some(Subcommand::Braid { dev: _ }) => {
let id = "braid_dev_node";
cli.run.shared_params.dev = true;
let runner = cli.create_runner(&cli.run)?;
runner.run_node_until_exit(|mut config| async move {
let chain_spec = cli.load_spec(id)?;
config.chain_spec = chain_spec;
set_default_ss58_version(&config.chain_spec);
cord_service::new_full(config, cli).map_err(sc_cli::Error::Service)
})
},
Some(Subcommand::Loom { dev: _ }) => {
let id = "loom_dev_node";
cli.run.shared_params.dev = true;
let runner = cli.create_runner(&cli.run)?;
runner.run_node_until_exit(|mut config| async move {
let chain_spec = cli.load_spec(id)?;
config.chain_spec = chain_spec;
set_default_ss58_version(&config.chain_spec);
cord_service::new_full(config, cli).map_err(sc_cli::Error::Service)
})
},
Some(Subcommand::Weave { dev: _ }) => {
let id = "weave_dev_node";
cli.run.shared_params.dev = true;
let runner = cli.create_runner(&cli.run)?;
runner.run_node_until_exit(|mut config| async move {
let chain_spec = cli.load_spec(id)?;
config.chain_spec = chain_spec;
set_default_ss58_version(&config.chain_spec);
cord_service::new_full(config, cli).map_err(sc_cli::Error::Service)
})
},
Some(Subcommand::Inspect(cmd)) => {
let runner = cli.create_runner(cmd)?;

Expand Down

0 comments on commit 25db2e8

Please sign in to comment.