Skip to content

Commit

Permalink
Change the regex to be lazy (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
yozhgoor authored Jun 28, 2021
1 parent 1f27732 commit 32c4073
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ 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`
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.
Expand Down
10 changes: 7 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Regex> = 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(),
Expand Down

0 comments on commit 32c4073

Please sign in to comment.