Skip to content

Commit

Permalink
chore(cli): refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-dn committed Sep 18, 2023
1 parent fde7b57 commit d6123f6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions core/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::args::{Args, Command};
use crate::commands::run::CustomStartShutdown;
use crate::commands::{dev, key, print_config, run};
use crate::config::TomlConfigProvider;
use crate::node::{FinalTypes, WithMockConsensus};
use crate::types::{FinalTypes, WithMockConsensus};
use crate::utils::fs::ensure_parent_exist;
use crate::utils::log_filter::CustomLogFilter;

Expand All @@ -30,20 +30,23 @@ impl Cli {
Self { args }
}

pub async fn run(self) -> Result<()> {
pub async fn exec(self) -> Result<()> {
self.setup();

let config_path = ResolvedPathBuf::try_from(self.args.config.as_str())
.expect("Failed to resolve config path");
ensure_parent_exist(&config_path)?;

match self.args.with_mock_consensus {
true => self.exec::<WithMockConsensus>(config_path, None).await,
false => self.exec::<FinalTypes>(config_path, None).await,
true => {
log::info!("Using MockConsensus");
self.run::<WithMockConsensus>(config_path, None).await
},
false => self.run::<FinalTypes>(config_path, None).await,
}
}

async fn exec<C>(
async fn run<C>(
self,
config_path: ResolvedPathBuf,
custom_start_shutdown: Option<CustomStartShutdown<C>>,
Expand Down
4 changes: 2 additions & 2 deletions core/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ mod args;
mod cli;
mod commands;
mod config;
mod node;
mod shutdown;
mod testnet_sync;
mod types;
mod utils;

use std::process::exit;
Expand All @@ -17,7 +17,7 @@ use crate::args::Args;
#[tokio::main]
async fn main() {
let cli = Cli::new(Args::parse());
if let Err(err) = cli.run().await {
if let Err(err) = cli.exec().await {
eprintln!("Command Failed.");
eprintln!("Error: {err}");
exit(-1);
Expand Down
File renamed without changes.

0 comments on commit d6123f6

Please sign in to comment.