Skip to content

Commit

Permalink
Add check_link_to_code
Browse files Browse the repository at this point in the history
  • Loading branch information
matias-gonz committed Jul 18, 2024
1 parent 56119d7 commit 4ff893f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
31 changes: 26 additions & 5 deletions zk_toolbox/crates/zk_inception/src/commands/ecosystem/create.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{path::PathBuf, str::FromStr};
use std::{
path::{Path, PathBuf},
str::FromStr,
};

use anyhow::bail;
use common::{git, logger, spinner::Spinner};
Expand All @@ -19,10 +22,11 @@ use crate::{
},
},
messages::{
msg_created_ecosystem, MSG_CLONING_ERA_REPO_SPINNER, MSG_CREATING_DEFAULT_CHAIN_SPINNER,
MSG_CREATING_ECOSYSTEM, MSG_CREATING_INITIAL_CONFIGURATIONS_SPINNER,
MSG_ECOSYSTEM_ALREADY_EXISTS_ERR, MSG_ECOSYSTEM_CONFIG_INVALID_ERR, MSG_SELECTED_CONFIG,
MSG_STARTING_CONTAINERS_SPINNER,
msg_created_ecosystem, msg_directory_does_not_contain_cargo_toml_err,
msg_path_to_zksync_does_not_exist_err, MSG_CLONING_ERA_REPO_SPINNER,
MSG_CREATING_DEFAULT_CHAIN_SPINNER, MSG_CREATING_ECOSYSTEM,
MSG_CREATING_INITIAL_CONFIGURATIONS_SPINNER, MSG_ECOSYSTEM_ALREADY_EXISTS_ERR,
MSG_ECOSYSTEM_CONFIG_INVALID_ERR, MSG_SELECTED_CONFIG, MSG_STARTING_CONTAINERS_SPINNER,
},
};

Expand Down Expand Up @@ -62,6 +66,7 @@ fn create(args: EcosystemCreateArgs, shell: &Shell) -> anyhow::Result<()> {
link_to_code
} else {
let path = PathBuf::from_str(&args.link_to_code)?;
check_link_to_code(&path)?;
git::submodule_update(shell, path.clone())?;
path
};
Expand Down Expand Up @@ -114,3 +119,19 @@ fn create(args: EcosystemCreateArgs, shell: &Shell) -> anyhow::Result<()> {
logger::outro(msg_created_ecosystem(ecosystem_name));
Ok(())
}

fn check_link_to_code(path: &Path) -> anyhow::Result<()> {
if !path.exists() {
bail!(msg_path_to_zksync_does_not_exist_err(
path.to_str().unwrap()
));
}

if !path.join("Cargo.toml").exists() {
bail!(msg_directory_does_not_contain_cargo_toml_err(
path.to_str().unwrap()
));
}

Ok(())
}
8 changes: 8 additions & 0 deletions zk_toolbox/crates/zk_inception/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ pub(super) const MSG_ECOSYSTEM_CONFIG_INVALID_ERR: &str = "Invalid ecosystem con
pub(super) const MSG_LINK_TO_CODE_SELECTION_CLONE: &str = "Clone for me (recommended)";
pub(super) const MSG_LINK_TO_CODE_SELECTION_PATH: &str = "I have the code already";

pub(super) fn msg_path_to_zksync_does_not_exist_err(path: &str) -> String {
format!("Path to ZkSync-era repo does not exist: {path:?}")
}

pub(super) fn msg_directory_does_not_contain_cargo_toml_err(path: &str) -> String {
format!("Directory does not contain Cargo.toml: {path:?}")
}

/// Ecosystem and chain init related messages
pub(super) const MSG_L1_RPC_URL_HELP: &str = "L1 RPC URL";
pub(super) const MSG_GENESIS_ARGS_HELP: &str = "Genesis options";
Expand Down

0 comments on commit 4ff893f

Please sign in to comment.