From 3fbd5aefd4bf47047924ce01e49106b78286146c Mon Sep 17 00:00:00 2001
From: kellda <59569234+kellda@users.noreply.github.com>
Date: Mon, 8 Jun 2020 12:48:47 +0000
Subject: [PATCH 1/3] Add `--index` flag to `cargo install`
---
src/bin/cargo/commands/install.rs | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs
index 55b5f116b65..b26c0cc6d4a 100644
--- a/src/bin/cargo/commands/install.rs
+++ b/src/bin/cargo/commands/install.rs
@@ -18,7 +18,7 @@ pub fn cli() -> App {
.arg(
opt("git", "Git URL to install the specified crate from")
.value_name("URL")
- .conflicts_with_all(&["path", "registry"]),
+ .conflicts_with_all(&["path", "index", "registry"]),
)
.arg(
opt("branch", "Branch to use when installing from git")
@@ -38,7 +38,7 @@ pub fn cli() -> App {
.arg(
opt("path", "Filesystem path to local crate to install")
.value_name("PATH")
- .conflicts_with_all(&["git", "registry"]),
+ .conflicts_with_all(&["git", "index", "registry"]),
)
.arg(opt(
"list",
@@ -58,11 +58,17 @@ pub fn cli() -> App {
)
.arg_target_triple("Build for the target triple")
.arg(opt("root", "Directory to install packages into").value_name("DIR"))
+ .arg(
+ opt("index", "Registry index to install from")
+ .value_name("INDEX")
+ .requires("crate")
+ .conflicts_with_all(&["git", "path", "registry"]),
+ )
.arg(
opt("registry", "Registry to use")
.value_name("REGISTRY")
.requires("crate")
- .conflicts_with_all(&["git", "path"]),
+ .conflicts_with_all(&["git", "path", "index"]),
)
.after_help(
"\
@@ -100,8 +106,6 @@ continuous integration systems.",
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
- let registry = args.registry(config)?;
-
if let Some(path) = args.value_of_path("path", config) {
config.reload_rooted_at(path)?;
} else {
@@ -143,8 +147,10 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
} else if krates.is_empty() {
from_cwd = true;
SourceId::for_path(config.cwd())?
- } else if let Some(registry) = registry {
+ } else if let Some(registry) = args.registry(config)? {
SourceId::alt_registry(config, ®istry)?
+ } else if let Some(index) = args.value_of("index") {
+ SourceId::for_registry(&index.into_url()?)?
} else {
SourceId::crates_io(config)?
};
From 1e0d38061c7c97f39de4ffb57eb354a5075cef31 Mon Sep 17 00:00:00 2001
From: kellda <59569234+kellda@users.noreply.github.com>
Date: Wed, 10 Jun 2020 15:21:37 +0000
Subject: [PATCH 2/3] Add test for `cargo install --index`
---
tests/testsuite/install.rs | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs
index 3761d0b11ab..842844819fa 100644
--- a/tests/testsuite/install.rs
+++ b/tests/testsuite/install.rs
@@ -9,7 +9,7 @@ use cargo_test_support::install::{
assert_has_installed_exe, assert_has_not_installed_exe, cargo_home,
};
use cargo_test_support::paths;
-use cargo_test_support::registry::Package;
+use cargo_test_support::registry::{registry_path, registry_url, Package};
use cargo_test_support::{
basic_manifest, cargo_process, no_such_file_err_msg, project, symlink_supported, t,
};
@@ -51,6 +51,35 @@ fn simple() {
assert_has_not_installed_exe(cargo_home(), "foo");
}
+#[cargo_test]
+fn with_index() {
+ pkg("foo", "0.0.1");
+
+ cargo_process("install foo --index")
+ .arg(registry_url().to_string())
+ .with_stderr(&format!(
+ "\
+[UPDATING] `{reg}` index
+[DOWNLOADING] crates ...
+[DOWNLOADED] foo v0.0.1 (registry `{reg}`)
+[INSTALLING] foo v0.0.1 (registry `{reg}`)
+[COMPILING] foo v0.0.1 (registry `{reg}`)
+[FINISHED] release [optimized] target(s) in [..]
+[INSTALLING] [CWD]/home/.cargo/bin/foo[EXE]
+[INSTALLED] package `foo v0.0.1 (registry `{reg}`)` (executable `foo[EXE]`)
+[WARNING] be sure to add `[..]` to your PATH to be able to run the installed binaries
+",
+ reg = registry_path().to_str().unwrap()
+ ))
+ .run();
+ assert_has_installed_exe(cargo_home(), "foo");
+
+ cargo_process("uninstall foo")
+ .with_stderr("[REMOVING] [CWD]/home/.cargo/bin/foo[EXE]")
+ .run();
+ assert_has_not_installed_exe(cargo_home(), "foo");
+}
+
#[cargo_test]
fn multiple_pkgs() {
pkg("foo", "0.0.1");
From a0fb62f5169fda1a4506cda8049f22e190831ba2 Mon Sep 17 00:00:00 2001
From: Eric Huss Install Options
If not specified, the default registry is used, which is defined by the
registry.default
config key which defaults to crates-io
.
The URL of the registry index to use.
+