Skip to content

Commit 56636e9

Browse files
committed
Auto merge of #8344 - kellda:install-index-flag, r=ehuss
Allow passing a registry index url directly to `cargo install` Fixes #8318
2 parents 79c769c + a0fb62f commit 56636e9

File tree

5 files changed

+55
-9
lines changed

5 files changed

+55
-9
lines changed

src/bin/cargo/commands/install.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn cli() -> App {
1818
.arg(
1919
opt("git", "Git URL to install the specified crate from")
2020
.value_name("URL")
21-
.conflicts_with_all(&["path", "registry"]),
21+
.conflicts_with_all(&["path", "index", "registry"]),
2222
)
2323
.arg(
2424
opt("branch", "Branch to use when installing from git")
@@ -38,7 +38,7 @@ pub fn cli() -> App {
3838
.arg(
3939
opt("path", "Filesystem path to local crate to install")
4040
.value_name("PATH")
41-
.conflicts_with_all(&["git", "registry"]),
41+
.conflicts_with_all(&["git", "index", "registry"]),
4242
)
4343
.arg(opt(
4444
"list",
@@ -58,11 +58,17 @@ pub fn cli() -> App {
5858
)
5959
.arg_target_triple("Build for the target triple")
6060
.arg(opt("root", "Directory to install packages into").value_name("DIR"))
61+
.arg(
62+
opt("index", "Registry index to install from")
63+
.value_name("INDEX")
64+
.requires("crate")
65+
.conflicts_with_all(&["git", "path", "registry"]),
66+
)
6167
.arg(
6268
opt("registry", "Registry to use")
6369
.value_name("REGISTRY")
6470
.requires("crate")
65-
.conflicts_with_all(&["git", "path"]),
71+
.conflicts_with_all(&["git", "path", "index"]),
6672
)
6773
.after_help(
6874
"\
@@ -100,8 +106,6 @@ continuous integration systems.",
100106
}
101107

102108
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
103-
let registry = args.registry(config)?;
104-
105109
if let Some(path) = args.value_of_path("path", config) {
106110
config.reload_rooted_at(path)?;
107111
} else {
@@ -143,8 +147,10 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
143147
} else if krates.is_empty() {
144148
from_cwd = true;
145149
SourceId::for_path(config.cwd())?
146-
} else if let Some(registry) = registry {
150+
} else if let Some(registry) = args.registry(config)? {
147151
SourceId::alt_registry(config, &registry)?
152+
} else if let Some(index) = args.value_of("index") {
153+
SourceId::for_registry(&index.into_url()?)?
148154
} else {
149155
SourceId::crates_io(config)?
150156
};

src/doc/man/cargo-install.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ available.
135135

136136
include::options-registry.adoc[]
137137

138+
include::options-index.adoc[]
139+
138140
include::options-features.adoc[]
139141

140142
=== Compilation Options

src/doc/man/generated/cargo-install.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ <h3 id="cargo_install_install_options">Install Options</h3>
197197
If not specified, the default registry is used, which is defined by the
198198
<code>registry.default</code> config key which defaults to <code>crates-io</code>.</p>
199199
</dd>
200+
<dt class="hdlist1"><strong>--index</strong> <em>INDEX</em></dt>
201+
<dd>
202+
<p>The URL of the registry index to use.</p>
203+
</dd>
200204
</dl>
201205
</div>
202206
</div>

src/etc/man/cargo-install.1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
.\" Title: cargo-install
33
.\" Author: [see the "AUTHOR(S)" section]
44
.\" Generator: Asciidoctor 2.0.10
5-
.\" Date: 2020-02-06
5+
.\" Date: 2020-06-14
66
.\" Manual: \ \&
77
.\" Source: \ \&
88
.\" Language: English
99
.\"
10-
.TH "CARGO\-INSTALL" "1" "2020-02-06" "\ \&" "\ \&"
10+
.TH "CARGO\-INSTALL" "1" "2020-06-14" "\ \&" "\ \&"
1111
.ie \n(.g .ds Aq \(aq
1212
.el .ds Aq '
1313
.ss \n[.ss] 0
@@ -293,6 +293,11 @@ Name of the registry to use. Registry names are defined in \c
293293
If not specified, the default registry is used, which is defined by the
294294
\fBregistry.default\fP config key which defaults to \fBcrates\-io\fP.
295295
.RE
296+
.sp
297+
\fB\-\-index\fP \fIINDEX\fP
298+
.RS 4
299+
The URL of the registry index to use.
300+
.RE
296301
.SS "Feature Selection"
297302
.sp
298303
The feature flags allow you to control the enabled features for the "current"

tests/testsuite/install.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use cargo_test_support::install::{
99
assert_has_installed_exe, assert_has_not_installed_exe, cargo_home,
1010
};
1111
use cargo_test_support::paths;
12-
use cargo_test_support::registry::Package;
12+
use cargo_test_support::registry::{registry_path, registry_url, Package};
1313
use cargo_test_support::{
1414
basic_manifest, cargo_process, no_such_file_err_msg, project, symlink_supported, t,
1515
};
@@ -51,6 +51,35 @@ fn simple() {
5151
assert_has_not_installed_exe(cargo_home(), "foo");
5252
}
5353

54+
#[cargo_test]
55+
fn with_index() {
56+
pkg("foo", "0.0.1");
57+
58+
cargo_process("install foo --index")
59+
.arg(registry_url().to_string())
60+
.with_stderr(&format!(
61+
"\
62+
[UPDATING] `{reg}` index
63+
[DOWNLOADING] crates ...
64+
[DOWNLOADED] foo v0.0.1 (registry `{reg}`)
65+
[INSTALLING] foo v0.0.1 (registry `{reg}`)
66+
[COMPILING] foo v0.0.1 (registry `{reg}`)
67+
[FINISHED] release [optimized] target(s) in [..]
68+
[INSTALLING] [CWD]/home/.cargo/bin/foo[EXE]
69+
[INSTALLED] package `foo v0.0.1 (registry `{reg}`)` (executable `foo[EXE]`)
70+
[WARNING] be sure to add `[..]` to your PATH to be able to run the installed binaries
71+
",
72+
reg = registry_path().to_str().unwrap()
73+
))
74+
.run();
75+
assert_has_installed_exe(cargo_home(), "foo");
76+
77+
cargo_process("uninstall foo")
78+
.with_stderr("[REMOVING] [CWD]/home/.cargo/bin/foo[EXE]")
79+
.run();
80+
assert_has_not_installed_exe(cargo_home(), "foo");
81+
}
82+
5483
#[cargo_test]
5584
fn multiple_pkgs() {
5685
pkg("foo", "0.0.1");

0 commit comments

Comments
 (0)