Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing a registry index url directly to cargo install #8344

Merged
merged 3 commits into from
Jun 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/bin/cargo/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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",
Expand All @@ -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(
"\
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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, &registry)?
} else if let Some(index) = args.value_of("index") {
SourceId::for_registry(&index.into_url()?)?
} else {
SourceId::crates_io(config)?
};
Expand Down
2 changes: 2 additions & 0 deletions src/doc/man/cargo-install.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ available.

include::options-registry.adoc[]

include::options-index.adoc[]

include::options-features.adoc[]

=== Compilation Options
Expand Down
4 changes: 4 additions & 0 deletions src/doc/man/generated/cargo-install.html
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ <h3 id="cargo_install_install_options">Install Options</h3>
If not specified, the default registry is used, which is defined by the
<code>registry.default</code> config key which defaults to <code>crates-io</code>.</p>
</dd>
<dt class="hdlist1"><strong>--index</strong> <em>INDEX</em></dt>
<dd>
<p>The URL of the registry index to use.</p>
</dd>
</dl>
</div>
</div>
Expand Down
9 changes: 7 additions & 2 deletions src/etc/man/cargo-install.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
.\" Title: cargo-install
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.10
.\" Date: 2020-02-06
.\" Date: 2020-06-14
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "CARGO\-INSTALL" "1" "2020-02-06" "\ \&" "\ \&"
.TH "CARGO\-INSTALL" "1" "2020-06-14" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
Expand Down Expand Up @@ -293,6 +293,11 @@ Name of the registry to use. Registry names are defined in \c
If not specified, the default registry is used, which is defined by the
\fBregistry.default\fP config key which defaults to \fBcrates\-io\fP.
.RE
.sp
\fB\-\-index\fP \fIINDEX\fP
.RS 4
The URL of the registry index to use.
.RE
.SS "Feature Selection"
.sp
The feature flags allow you to control the enabled features for the "current"
Expand Down
31 changes: 30 additions & 1 deletion tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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");
Expand Down