1use super::cmd::LocalCmd;
2use crate::{
3 chain_config::{check_and_update_chain_config, ChainConfig},
4 run_opts::{DbType, RunOpts},
5 util::HumanReadableCommand,
6};
7use anyhow::Context;
8use forc_tracing::println_green;
9use std::process::{Child, Command};
10
11pub(crate) async fn run(cmd: LocalCmd, dry_run: bool) -> anyhow::Result<Option<Child>> {
15 check_and_update_chain_config(ChainConfig::Local).await?;
16
17 let run_opts = RunOpts::from(cmd);
18 let params = run_opts.generate_params();
19
20 let mut fuel_core_command = Command::new("fuel-core");
21 fuel_core_command.arg("run");
22 fuel_core_command.args(params.as_slice());
23
24 println_green(&format!(
25 "{}",
26 HumanReadableCommand::from(&fuel_core_command)
27 ));
28
29 if dry_run {
30 Ok(None)
31 } else {
32 let handle = fuel_core_command
34 .spawn()
35 .with_context(|| "Failed to spawn fuel-core process:".to_string())?;
36
37 Ok(Some(handle))
38 }
39}
40
41impl From<LocalCmd> for RunOpts {
42 fn from(value: LocalCmd) -> Self {
43 let path = value
44 .chain_config
45 .unwrap_or_else(|| ChainConfig::Local.into());
46 let db_type = value
47 .db_path
48 .as_ref()
49 .map_or(DbType::InMemory, |_| DbType::RocksDb);
50 Self {
51 db_type,
52 debug: true,
53 snapshot: path,
54 poa_instant: true,
55 db_path: value.db_path,
56 port: value.port,
57 ..Default::default()
58 }
59 }
60}