Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve path error and improve versioning error #57

Merged
merged 5 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions crates/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&current_path)
} else {
loop {
// TODO, add TargetType::File path input here
Expand All @@ -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}")
Expand Down
9 changes: 9 additions & 0 deletions crates/cli/src/utils.rs
Original file line number Diff line number Diff line change
@@ -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(
"
Expand All @@ -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::<Vec<&str>>();
if version_list.len() != SCARB_VERSION_OUTPUT_LINES {
panic!("{}", String::from_utf8(versioning.stderr).unwrap());
}
let scarb_version = versioning_str.split('\n').collect::<Vec<&str>>()[0]
.split(" ")
.collect::<Vec<&str>>()[1];
Expand Down
Loading