use std::{path::{Path, PathBuf}, process::Command};
use colored::Colorize;
use crate::cli::{BuildProfile, RunArgs};
use crate::embargo_toml::{ConfigFile, EmbargoFile};
use crate::error::EmbargoResult;
use super::build_project;
pub fn run_project(run_args: &RunArgs, embargo_toml: &EmbargoFile, embargo_toml_path: &Path) -> EmbargoResult {
build_project(&run_args.build_args, embargo_toml, embargo_toml_path)?;
let mut exec_path = embargo_toml_path.to_path_buf();
let mut final_run_path = PathBuf::new();
exec_path.push(embargo_toml.build_path());
final_run_path.push(embargo_toml.build_path());
match run_args.build_args.profile {
BuildProfile::Debug => {
exec_path.push(embargo_toml.target_path_debug());
},
BuildProfile::Release => {
exec_path.push(embargo_toml.target_path_release());
}
}
exec_path.push(embargo_toml.bin_path());
let exec_cwd = exec_path.clone();
exec_path.push(&embargo_toml.package.name);
let args: Vec<&str> = vec![];
println!("{} \"{}\"", "Running".green().bold(), exec_path.display());
let mut run = Command::new(exec_path);
let run = run
.current_dir(exec_cwd)
.args(args);
run.spawn()?;
Ok(None)
}