Skip to content

Commit

Permalink
removed the url from the config
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-eth committed May 5, 2024
1 parent c4fb849 commit 16eea6e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = "MIT"
name = "soldeer"
readme = "./README.md"
repository = "https://github.com/mario-eth/soldeer"
version = "0.2.9"
version = "0.2.10"

[dependencies]
chrono = {version = "0.4.37", features = ["serde"]}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This project was started to solve the following issues:
- npmjs was built for the js ecosystem not for solidity
- github versioning of the releases is a pain and not all the projects are using it correctly

## Version 0.2.9
## Version 0.2.10

### Version 0.2.7 introduces the following breaking changes

Expand Down
38 changes: 27 additions & 11 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::errors::ConfigError;
use crate::janitor::cleanup_dependency;
use crate::lock::remove_lock;
use crate::remote::get_dependency_url_remote;
use crate::utils::{
get_current_working_dir,
read_file_to_string,
Expand Down Expand Up @@ -50,7 +51,7 @@ struct Foundry {
remappings: Table,
}

pub fn read_config(filename: String) -> Result<Vec<Dependency>, ConfigError> {
pub async fn read_config(filename: String) -> Result<Vec<Dependency>, ConfigError> {
let mut filename: String = filename;
if filename.is_empty() {
filename = match define_config_file() {
Expand All @@ -76,13 +77,25 @@ pub fn read_config(filename: String) -> Result<Vec<Dependency>, ConfigError> {
};

let mut dependencies: Vec<Dependency> = Vec::new();
data.dependencies.iter().for_each(|(k, v)| {
dependencies.push(Dependency {
name: k.to_string(),
version: v["version"].to_string().replace('"', ""),
url: v["url"].to_string().replace('\"', ""),
});
});
let iterator = data.dependencies.iter();
for (k, v) in iterator {
let url;
let version = v["version"].to_string().replace('"', "");
let name = k.to_string();
if v.get("url").is_some() {
url = v["url"].to_string().replace('\"', "");
} else {
match get_dependency_url_remote(&name, &version).await {
Ok(u) => url = u,
Err(_) => {
return Err(ConfigError {
cause: "Could not get the url".to_string(),
});
}
}
}
dependencies.push(Dependency { name, version, url });
}

Ok(dependencies)
}
Expand Down Expand Up @@ -166,6 +179,7 @@ pub fn add_to_config(
dependency_name: &str,
dependency_version: &str,
dependency_url: &str,
custom_url: bool,
) -> Result<(), ConfigError> {
println!(
"{}",
Expand Down Expand Up @@ -243,7 +257,9 @@ pub fn add_to_config(

let mut new_item: Item = Item::None;
new_item["version"] = value(dependency_version);
new_item["url"] = value(dependency_url);
if custom_url {
new_item["url"] = value(dependency_url);
}
doc["dependencies"]
.as_table_mut()
.unwrap()
Expand All @@ -259,7 +275,7 @@ pub fn add_to_config(
Ok(())
}

pub fn remappings() -> Result<(), ConfigError> {
pub async fn remappings() -> Result<(), ConfigError> {
let remappings_path = get_current_working_dir().unwrap().join("remappings.txt");
if !remappings_path.exists() {
File::create(remappings_path.clone()).unwrap();
Expand All @@ -269,7 +285,7 @@ pub fn remappings() -> Result<(), ConfigError> {
let existing_remappings: Vec<String> = contents.split('\n').map(|s| s.to_string()).collect();
let mut new_remappings: String = String::new();

let dependencies: Vec<Dependency> = match read_config(String::new()) {
let dependencies: Vec<Dependency> = match read_config(String::new()).await {
Ok(dep) => dep,
Err(err) => {
return Err(err);
Expand Down
15 changes: 11 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ pub async fn run(command: Subcommands) -> Result<(), SoldeerError> {
let dependency_version: String =
install.dependency.split('~').collect::<Vec<&str>>()[1].to_string();
let dependency_url: String;
let mut custom_url = false;
if install.remote_url.is_some() {
custom_url = true;
let remote_url = install.remote_url.unwrap();
let mut dependencies: Vec<Dependency> = Vec::new();
dependency_url = remote_url.clone();
Expand Down Expand Up @@ -170,7 +172,12 @@ pub async fn run(command: Subcommands) -> Result<(), SoldeerError> {
}
}

match config::add_to_config(&dependency_name, &dependency_version, &dependency_url) {
match config::add_to_config(
&dependency_name,
&dependency_version,
&dependency_url,
custom_url,
) {
Ok(_) => {}
Err(err) => {
return Err(SoldeerError { message: err.cause });
Expand Down Expand Up @@ -209,7 +216,7 @@ pub async fn run(command: Subcommands) -> Result<(), SoldeerError> {
};

if foundry_setup.remappings {
match remappings() {
match remappings().await {
Ok(_) => {}
Err(err) => {
return Err(SoldeerError { message: err.cause });
Expand All @@ -220,7 +227,7 @@ pub async fn run(command: Subcommands) -> Result<(), SoldeerError> {
Subcommands::Update(_) => {
println!("{}", Paint::green("🦌 Running soldeer update 🦌\n"));

let dependencies: Vec<Dependency> = match read_config(String::new()) {
let dependencies: Vec<Dependency> = match read_config(String::new()).await {
Ok(dep) => dep,
Err(err) => return Err(SoldeerError { message: err.cause }),
};
Expand Down Expand Up @@ -288,7 +295,7 @@ pub async fn run(command: Subcommands) -> Result<(), SoldeerError> {
};

if foundry_setup.remappings {
match remappings() {
match remappings().await {
Ok(_) => {}
Err(err) => {
return Err(SoldeerError { message: err.cause });
Expand Down

0 comments on commit 16eea6e

Please sign in to comment.