diff --git a/Cargo.lock b/Cargo.lock index 3bb7a03..b412c8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -48,6 +48,7 @@ dependencies = [ "cargo-temp-bindings", "clap", "dirs", + "once_cell", "regex", "serde", "tempfile", @@ -189,6 +190,12 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" +[[package]] +name = "once_cell" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" + [[package]] name = "os_str_bytes" version = "2.4.0" diff --git a/Cargo.toml b/Cargo.toml index 9f167a4..d9d728c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ serde = { version = "1.0", features = ["derive"] } tempfile = "3" toml = "0.5" regex = "1.5.4" +once_cell = "1.8.0" [target.'cfg(windows)'.dependencies] cargo-temp-bindings = { path = "cargo-temp-bindings", version = "^0.0" } diff --git a/README.md b/README.md index 0bfd7ba..668dbf7 100644 --- a/README.md +++ b/README.md @@ -58,14 +58,14 @@ When you run `cargo-temp` for the first time it will be created automatically. We use the [XDG system](https://docs.rs/xdg/2.2.0/xdg/) for both Linux and OSX and the [Know Folder system](https://docs.rs/dirs-2/3.0.1/dirs_2/) on Windows. -### `temporary_project_dir` +### Temporary project directory The path where the temporary projects are created. Set on the cache directory by default. `temporary_project_dir = "/home/name/.cache/cargo-temp/"` -### `cargo_target_dir` +### Cargo target directory Cargo's target directory override. This setting is unset by default and will be ignored if the `CARGO_TARGET_DIR` @@ -73,7 +73,7 @@ environment variable is already set. `temporary_project_dir = "/home/name/repos/tmp"` -### editor +### Editor You can use `editor` to start an IDE instead of a shell and `editor_args` to provide its arguments. These settings are unset by default. diff --git a/src/main.rs b/src/main.rs index 15655c2..6301ca4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use anyhow::{bail, Context, Result}; use clap::Clap; +use once_cell::sync::Lazy; use regex::Regex; use serde::{Deserialize, Serialize}; use std::io::Write; @@ -226,11 +227,14 @@ fn get_shell() -> String { } fn parse_dependency(s: &str) -> Dependency { - let regex = + // This will change when `std::lazy` is released. + // See https://github.com/rust-lang/rust/issues/74465. + static RE: Lazy = Lazy::new(|| { Regex::new(r"^([^=]+)=(((\w+://([^:@]+(:[^@]+)?@)?[^#]+)(#branch=(.+)|#rev=(.+))?)|.+)$") - .unwrap(); + .unwrap() + }); - if let Some(caps) = regex.captures(s) { + if let Some(caps) = RE.captures(s) { if let Some(url) = caps.get(4) { Dependency::Repository { name: caps[1].to_string(),