diff --git a/crates/cli/src/cli.rs b/crates/cli/src/cli.rs index ff2bbfb..2a30f36 100644 --- a/crates/cli/src/cli.rs +++ b/crates/cli/src/cli.rs @@ -51,8 +51,9 @@ fn main() -> anyhow::Result<()> { // Project type + Path entry let target_type = TargetType::ScarbProject; // by default we assume the user is in a scarb project let is_current_dir_scarb = env::current_dir()?.join("scarb.toml").exists(); - let path = if is_current_dir_scarb { - env::current_dir()?.to_str().unwrap().trim().to_string() + let utf8_path = if is_current_dir_scarb { + let current_path = env::current_dir()?.to_str().unwrap().trim().to_string(); + Utf8PathBuf::from(¤t_path) } else { loop { // TODO, add TargetType::File path input here @@ -62,22 +63,21 @@ fn main() -> anyhow::Result<()> { .expect("Aborted at path input, terminating...") .trim() .to_string(); - let utf8_path: Utf8PathBuf = Utf8PathBuf::from(&input_path); - if utf8_path.exists() { - break input_path; + let mut utf8_input_path: Utf8PathBuf = Utf8PathBuf::from(&input_path); + // Resolve path + if utf8_input_path.starts_with("~") { + if let Some(home) = home_dir() { + let home_utf8 = Utf8PathBuf::from_path_buf(home).unwrap(); + utf8_input_path = home_utf8.join(utf8_input_path.strip_prefix("~").unwrap()); + } + } + if utf8_input_path.exists() { + break utf8_input_path; } else { println!("Path does not exist. Please try again."); } } }; - // Resolve path - let mut utf8_path = Utf8PathBuf::from(&path); - if utf8_path.starts_with("~") { - if let Some(home) = home_dir() { - let home_utf8 = Utf8PathBuf::from_path_buf(home).unwrap(); - utf8_path = home_utf8.join(utf8_path.strip_prefix("~").unwrap()); - } - } // Start the whole process let _spinner_style = ProgressStyle::with_template("{prefix:.bold.dim} {spinner} {wide_msg}") diff --git a/crates/cli/src/utils.rs b/crates/cli/src/utils.rs index 89855a6..62c31ef 100644 --- a/crates/cli/src/utils.rs +++ b/crates/cli/src/utils.rs @@ -1,6 +1,8 @@ use dyn_compiler::dyn_compiler::{SupportedCairoVersions, SupportedScarbVersions}; use std::process::Command; +const SCARB_VERSION_OUTPUT_LINES: usize = 3; + pub fn detect_local_tools() -> (SupportedScarbVersions, SupportedCairoVersions) { let versioning = Command::new("scarb").arg("--version").output().expect( " @@ -11,6 +13,13 @@ pub fn detect_local_tools() -> (SupportedScarbVersions, SupportedCairoVersions) ); let versioning_str = String::from_utf8(versioning.stdout).unwrap(); + let version_list = versioning_str + .split('\n') + .filter(|x| !x.is_empty()) + .collect::>(); + if version_list.len() != SCARB_VERSION_OUTPUT_LINES { + panic!("{}", String::from_utf8(versioning.stderr).unwrap()); + } let scarb_version = versioning_str.split('\n').collect::>()[0] .split(" ") .collect::>()[1];