-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
214: Allow simultaneous specification of both version and path r=ordian a=dherman Closes #213. Co-authored-by: David Herman <[email protected]>
- Loading branch information
Showing
5 changed files
with
221 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,14 +53,16 @@ $ # Add a non-crates.io crate | |
$ cargo add local_experiment --path=lib/trial-and-error/ | ||
$ # Add a non-crates.io crate; the crate name will be found automatically | ||
$ cargo add lib/trial-and-error/ | ||
$ # Add a crates.io crate with a local development path | ||
$ cargo add my_helper --vers=1.3.1 --path=lib/my-helper/ | ||
``` | ||
|
||
#### Usage | ||
|
||
```plain | ||
$ cargo add --help | ||
Usage: | ||
cargo add <crate> [--dev|--build|--optional] [--vers=<ver>|--git=<uri>|--path=<uri>] [options] | ||
cargo add <crate> [--dev|--build|--optional] [options] | ||
cargo add <crates>... [--dev|--build|--optional] [options] | ||
cargo add (-h|--help) | ||
cargo add --version | ||
|
@@ -69,7 +71,8 @@ Specify what crate to add: | |
--vers <ver> Specify the version to grab from the registry (crates.io). | ||
You can also specify versions as part of the name, e.g | ||
`cargo add [email protected]`. | ||
--git <uri> Specify a git repository to download the crate from. | ||
--git <uri> Specify a git repository to download the crate from. This does not work | ||
if either a version or path (or both) is specified. | ||
--path <uri> Specify the path the crate should be loaded from. | ||
Specify where to add the crate: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,18 @@ use args::Args; | |
|
||
mod errors { | ||
error_chain!{ | ||
errors { | ||
/// Specified a dependency with both a git URL and a version. | ||
GitUrlWithVersion(git: String, version: String) { | ||
description("Specified git URL with version") | ||
display("Cannot specify a git URL (`{}`) with a version (`{}`).", git, version) | ||
} | ||
/// Specified a dependency with both a git URL and a path. | ||
GitUrlWithPath(git: String, path: String) { | ||
description("Specified git URL with path") | ||
display("Cannot specify a git URL (`{}`) with a path (`{}`).", git, path) | ||
} | ||
} | ||
links { | ||
CargoEditLib(::cargo_edit::Error, ::cargo_edit::ErrorKind); | ||
} | ||
|
@@ -38,7 +50,7 @@ use errors::*; | |
|
||
static USAGE: &'static str = r#" | ||
Usage: | ||
cargo add <crate> [--dev|--build|--optional] [--vers=<ver>|--git=<uri>|--path=<uri>] [options] | ||
cargo add <crate> [--dev|--build|--optional] [options] | ||
cargo add <crates>... [--dev|--build|--optional] [options] | ||
cargo add (-h|--help) | ||
cargo add --version | ||
|
@@ -47,7 +59,8 @@ Specify what crate to add: | |
--vers <ver> Specify the version to grab from the registry (crates.io). | ||
You can also specify versions as part of the name, e.g | ||
`cargo add [email protected]`. | ||
--git <uri> Specify a git repository to download the crate from. | ||
--git <uri> Specify a git repository to download the crate from. This does not work | ||
if either a version or path (or both) is specified. | ||
--path <uri> Specify the path the crate should be loaded from. | ||
Specify where to add the crate: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -419,13 +419,120 @@ fn adds_local_source_without_flag() { | |
} | ||
|
||
#[test] | ||
fn package_kinds_are_mutually_exclusive() { | ||
fn adds_local_source_with_version_flag() { | ||
let (_tmpdir, manifest) = clone_out_test("tests/fixtures/add/Cargo.toml.sample"); | ||
|
||
// dependency not present beforehand | ||
let toml = get_toml(&manifest); | ||
assert!(toml["dependencies"].is_none()); | ||
|
||
execute_command( | ||
&["add", "local", "--vers", "0.4.3", "--path", "/path/to/pkg"], | ||
&manifest, | ||
); | ||
|
||
let toml = get_toml(&manifest); | ||
let val = &toml["dependencies"]["local"]; | ||
assert_eq!(val["path"].as_str(), Some("/path/to/pkg")); | ||
assert_eq!(val["version"].as_str(), Some("0.4.3")); | ||
|
||
// check this works with other flags (e.g. --dev) as well | ||
let toml = get_toml(&manifest); | ||
assert!(toml["dev-dependencies"].is_none()); | ||
|
||
execute_command( | ||
&[ | ||
"add", | ||
"local-dev", | ||
"--vers", | ||
"0.4.3", | ||
"--path", | ||
"/path/to/pkg-dev", | ||
"--dev", | ||
], | ||
&manifest, | ||
); | ||
|
||
let toml = get_toml(&manifest); | ||
let val = &toml["dev-dependencies"]["local-dev"]; | ||
assert_eq!(val["path"].as_str(), Some("/path/to/pkg-dev")); | ||
assert_eq!(val["version"].as_str(), Some("0.4.3")); | ||
} | ||
|
||
#[test] | ||
fn adds_local_source_with_inline_version_notation() { | ||
let (_tmpdir, manifest) = clone_out_test("tests/fixtures/add/Cargo.toml.sample"); | ||
|
||
// dependency not present beforehand | ||
let toml = get_toml(&manifest); | ||
assert!(toml["dependencies"].is_none()); | ||
|
||
execute_command(&["add", "[email protected]", "--path", "/path/to/pkg"], &manifest); | ||
|
||
let toml = get_toml(&manifest); | ||
let val = &toml["dependencies"]["local"]; | ||
assert_eq!(val["path"].as_str(), Some("/path/to/pkg")); | ||
assert_eq!(val["version"].as_str(), Some("0.4.3")); | ||
|
||
// check this works with other flags (e.g. --dev) as well | ||
let toml = get_toml(&manifest); | ||
assert!(toml["dev-dependencies"].is_none()); | ||
|
||
execute_command( | ||
&[ | ||
"add", | ||
"[email protected]", | ||
"--path", | ||
"/path/to/pkg-dev", | ||
"--dev", | ||
], | ||
&manifest, | ||
); | ||
|
||
let toml = get_toml(&manifest); | ||
let val = &toml["dev-dependencies"]["local-dev"]; | ||
assert_eq!(val["path"].as_str(), Some("/path/to/pkg-dev")); | ||
assert_eq!(val["version"].as_str(), Some("0.4.3")); | ||
} | ||
|
||
#[test] | ||
fn git_and_version_flags_are_mutually_exclusive() { | ||
let (_tmpdir, manifest) = clone_out_test("tests/fixtures/add/Cargo.toml.sample"); | ||
|
||
let call = process::Command::new("target/debug/cargo-add") | ||
.args(&["add", BOGUS_CRATE_NAME]) | ||
.args(&["--vers", "0.4.3"]) | ||
.args(&["--git", "git://git.git"]) | ||
.arg(format!("--manifest-path={}", &manifest)) | ||
.output() | ||
.unwrap(); | ||
|
||
assert!(!call.status.success()); | ||
assert!(no_manifest_failures(&get_toml(&manifest).root)); | ||
} | ||
|
||
#[test] | ||
fn git_flag_and_inline_version_are_mutually_exclusive() { | ||
let (_tmpdir, manifest) = clone_out_test("tests/fixtures/add/Cargo.toml.sample"); | ||
|
||
let call = process::Command::new("target/debug/cargo-add") | ||
.args(&["add", &format!("{}@0.4.3", BOGUS_CRATE_NAME)]) | ||
.args(&["--git", "git://git.git"]) | ||
.arg(format!("--manifest-path={}", &manifest)) | ||
.output() | ||
.unwrap(); | ||
|
||
assert!(!call.status.success()); | ||
assert!(no_manifest_failures(&get_toml(&manifest).root)); | ||
} | ||
|
||
#[test] | ||
fn git_and_path_are_mutually_exclusive() { | ||
let (_tmpdir, manifest) = clone_out_test("tests/fixtures/add/Cargo.toml.sample"); | ||
|
||
let call = process::Command::new("target/debug/cargo-add") | ||
.args(&["add", BOGUS_CRATE_NAME]) | ||
.args(&["--git", "git://git.git"]) | ||
.args(&["--path", "/path/here"]) | ||
.arg(format!("--manifest-path={}", &manifest)) | ||
.output() | ||
|
@@ -730,7 +837,7 @@ fn no_argument() { | |
r"Invalid arguments. | ||
Usage: | ||
cargo add <crate> [--dev|--build|--optional] [--vers=<ver>|--git=<uri>|--path=<uri>] [options] | ||
cargo add <crate> [--dev|--build|--optional] [options] | ||
cargo add <crates>... [--dev|--build|--optional] [options] | ||
cargo add (-h|--help) | ||
cargo add --version", | ||
|
@@ -746,7 +853,7 @@ fn unknown_flags() { | |
r"Unknown flag: '--flag' | ||
Usage: | ||
cargo add <crate> [--dev|--build|--optional] [--vers=<ver>|--git=<uri>|--path=<uri>] [options] | ||
cargo add <crate> [--dev|--build|--optional] [options] | ||
cargo add <crates>... [--dev|--build|--optional] [options] | ||
cargo add (-h|--help) | ||
cargo add --version", | ||
|