diff --git a/crates/cli/src/opts/dependency.rs b/crates/cli/src/opts/dependency.rs index b7fe20abfc40..c3d802dbe208 100644 --- a/crates/cli/src/opts/dependency.rs +++ b/crates/cli/src/opts/dependency.rs @@ -8,7 +8,7 @@ static GH_REPO_REGEX: LazyLock = LazyLock::new(|| Regex::new(r"[\w-]+/[\w /// Git repo prefix regex pub static GH_REPO_PREFIX_REGEX: LazyLock = LazyLock::new(|| { - Regex::new(r"((git@)|(git\+https://)|(https://)|(org-([A-Za-z0-9-])+@))?(?P[A-Za-z0-9-]+)\.(?P[A-Za-z0-9-]+)(/|:)") + Regex::new(r"((git@)|(git\+https://)|(https://)|https://(?P[^@]+)@|(org-([A-Za-z0-9-])+@))?(?P[A-Za-z0-9-]+)\.(?P[A-Za-z0-9-]+)(/|:)") .unwrap() }); @@ -81,7 +81,15 @@ impl FromStr for Dependency { let brand = captures.name("brand").unwrap().as_str(); let tld = captures.name("tld").unwrap().as_str(); let project = GH_REPO_PREFIX_REGEX.replace(dependency, ""); - Some(format!("https://{brand}.{tld}/{}", project.trim_end_matches(".git"))) + if let Some(token) = captures.name("token") { + Some(format!( + "https://{}@{brand}.{tld}/{}", + token.as_str(), + project.trim_end_matches(".git") + )) + } else { + Some(format!("https://{brand}.{tld}/{}", project.trim_end_matches(".git"))) + } } else { // If we don't have a URL and we don't have a valid // GitHub repository name, then we assume this is the alias. @@ -392,4 +400,18 @@ mod tests { assert_eq!(dep.tag, Some("80eb41b".to_string())); assert_eq!(dep.alias, None); } + + #[test] + fn can_parse_https_with_github_token() { + // + let dep = Dependency::from_str( + "https://ghp_mytoken@github.com/private-org/precompiles-solidity.git", + ) + .unwrap(); + assert_eq!(dep.name, "precompiles-solidity"); + assert_eq!( + dep.url, + Some("https://ghp_mytoken@github.com/private-org/precompiles-solidity".to_string()) + ); + } } diff --git a/crates/forge/bin/cmd/install.rs b/crates/forge/bin/cmd/install.rs index 55eb4f5d4b6b..ee1b3a4ab73a 100644 --- a/crates/forge/bin/cmd/install.rs +++ b/crates/forge/bin/cmd/install.rs @@ -24,6 +24,7 @@ static DEPENDENCY_VERSION_TAG_REGEX: LazyLock = #[command(override_usage = "forge install [OPTIONS] [DEPENDENCIES]... forge install [OPTIONS] /@... forge install [OPTIONS] =/@... + forge install [OPTIONS] @git url>...)] forge install [OPTIONS] ...")] pub struct InstallArgs { /// The dependencies to install.