From f40e225b32ba53dec3456275fdc95646974f9c02 Mon Sep 17 00:00:00 2001 From: mstrong Date: Tue, 23 Jul 2024 09:01:16 -0400 Subject: [PATCH 1/4] resolve tilda path issue --- crates/cli/src/cli.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/crates/cli/src/cli.rs b/crates/cli/src/cli.rs index d35fd7f..8bcfef5 100644 --- a/crates/cli/src/cli.rs +++ b/crates/cli/src/cli.rs @@ -13,7 +13,6 @@ use console::{style, Emoji}; use dialoguer::{theme::ColorfulTheme, Confirm, Input, Select}; use dirs::home_dir; use indicatif::{HumanDuration, ProgressStyle}; -use regex::Regex; use std::{env, str::FromStr, time::Instant}; use strum::IntoEnumIterator; use validation::is_class_hash_valid; @@ -59,7 +58,14 @@ fn main() -> anyhow::Result<()> { .expect("Aborted at path input, terminating...") .trim() .to_string(); - let utf8_path: Utf8PathBuf = Utf8PathBuf::from(&input_path); + let mut utf8_path: Utf8PathBuf = Utf8PathBuf::from(&input_path); + // Resolve 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()); + } + } if utf8_path.exists() { break input_path; } else { @@ -67,14 +73,7 @@ fn main() -> anyhow::Result<()> { } } }; - // 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()); - } - } + let utf8_path = Utf8PathBuf::from(&path); // Start the whole process let _spinner_style = ProgressStyle::with_template("{prefix:.bold.dim} {spinner} {wide_msg}") From 73a414f6dc419d0ab8918ba66c75907342c9a27b Mon Sep 17 00:00:00 2001 From: mstrong Date: Tue, 23 Jul 2024 09:01:53 -0400 Subject: [PATCH 2/4] versioning check --- crates/cli/src/utils.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/cli/src/utils.rs b/crates/cli/src/utils.rs index 89855a6..f614089 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,10 @@ 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]; From 7b57d6016608f5e35f7394276e7ca4e1dcd88a46 Mon Sep 17 00:00:00 2001 From: liam Date: Tue, 23 Jul 2024 10:13:27 -0400 Subject: [PATCH 3/4] fmt --- crates/cli/src/utils.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/cli/src/utils.rs b/crates/cli/src/utils.rs index f614089..62c31ef 100644 --- a/crates/cli/src/utils.rs +++ b/crates/cli/src/utils.rs @@ -13,7 +13,10 @@ 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::>(); + 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()); } From 65ef614c5199720fefa9f37d2ff3ff0105c9b260 Mon Sep 17 00:00:00 2001 From: liam Date: Wed, 24 Jul 2024 08:54:38 -0400 Subject: [PATCH 4/4] resolve tilda path --- crates/cli/src/cli.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/cli/src/cli.rs b/crates/cli/src/cli.rs index 8bcfef5..9312b87 100644 --- a/crates/cli/src/cli.rs +++ b/crates/cli/src/cli.rs @@ -47,8 +47,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 @@ -58,22 +59,21 @@ fn main() -> anyhow::Result<()> { .expect("Aborted at path input, terminating...") .trim() .to_string(); - let mut utf8_path: Utf8PathBuf = Utf8PathBuf::from(&input_path); + let mut utf8_input_path: Utf8PathBuf = Utf8PathBuf::from(&input_path); // Resolve path - if utf8_path.starts_with("~") { + if utf8_input_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()); + utf8_input_path = home_utf8.join(utf8_input_path.strip_prefix("~").unwrap()); } } - if utf8_path.exists() { - break input_path; + if utf8_input_path.exists() { + break utf8_input_path; } else { println!("Path does not exist. Please try again."); } } }; - let utf8_path = Utf8PathBuf::from(&path); // Start the whole process let _spinner_style = ProgressStyle::with_template("{prefix:.bold.dim} {spinner} {wide_msg}")