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

cargo install: Be more restrictive about cli flags. #6801

Merged
merged 1 commit into from
Apr 1, 2019
Merged
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
58 changes: 42 additions & 16 deletions src/bin/cargo/commands/install.rs
Original file line number Diff line number Diff line change
@@ -10,15 +10,36 @@ pub fn cli() -> App {
.arg(opt("quiet", "No output printed to stdout").short("q"))
.arg(Arg::with_name("crate").empty_values(false).multiple(true))
.arg(
opt("version", "Specify a version to install from crates.io")
opt("version", "Specify a version to install")
.alias("vers")
.value_name("VERSION"),
.value_name("VERSION")
.requires("crate"),
)
.arg(
opt("git", "Git URL to install the specified crate from")
.value_name("URL")
.conflicts_with_all(&["path", "registry"]),
)
.arg(
opt("branch", "Branch to use when installing from git")
.value_name("BRANCH")
.requires("git"),
)
.arg(
opt("tag", "Tag to use when installing from git")
.value_name("TAG")
.requires("git"),
)
.arg(
opt("rev", "Specific commit to use when installing from git")
.value_name("SHA")
.requires("git"),
)
.arg(
opt("path", "Filesystem path to local crate to install")
.value_name("PATH")
.conflicts_with_all(&["git", "registry"]),
)
.arg(opt("git", "Git URL to install the specified crate from").value_name("URL"))
.arg(opt("branch", "Branch to use when installing from git").value_name("BRANCH"))
.arg(opt("tag", "Tag to use when installing from git").value_name("TAG"))
.arg(opt("rev", "Specific commit to use when installing from git").value_name("SHA"))
.arg(opt("path", "Filesystem path to local crate to install").value_name("PATH"))
.arg(opt(
"list",
"list all installed packages and their versions",
@@ -35,7 +56,12 @@ 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("registry", "Registry to use").value_name("REGISTRY"))
.arg(
opt("registry", "Registry to use")
.value_name("REGISTRY")
.requires("crate")
.conflicts_with_all(&["git", "path"]),
)
.after_help(
"\
This command manages Cargo's local set of installed binary crates. Only packages
@@ -46,10 +72,10 @@ configuration key, and finally the home directory (which is either
`$CARGO_HOME` if set or `$HOME/.cargo` by default).

There are multiple sources from which a crate can be installed. The default
location is crates.io but the `--git` and `--path` flags can change this source.
If the source contains more than one package (such as crates.io or a git
repository with multiple crates) the `<crate>` argument is required to indicate
which crate should be installed.
location is crates.io but the `--git`, `--path`, and `registry` flags can
change this source. If the source contains more than one package (such as
crates.io or a git repository with multiple crates) the `<crate>` argument is
required to indicate which crate should be installed.

Crates from crates.io can optionally specify the version they wish to install
via the `--version` flags, and similarly packages from git repositories can
@@ -62,10 +88,10 @@ By default cargo will refuse to overwrite existing binaries. The `--force` flag
enables overwriting existing binaries. Thus you can reinstall a crate with
`cargo install --force <crate>`.

Omitting the <crate> specification entirely will
install the crate in the current directory. That is, `install` is equivalent to
the more explicit `install --path .`. This behaviour is deprecated, and no
longer supported as of the Rust 2018 edition.
Omitting the <crate> specification entirely will install the crate in the
current directory. That is, `install` is equivalent to the more explicit
`install --path .`. This behaviour is deprecated, and no longer supported as
of the Rust 2018 edition.

If the source is crates.io or `--git` then by default the crate will be built
in a temporary target directory. To avoid this, the target directory can be
10 changes: 5 additions & 5 deletions src/doc/man/cargo-install.adoc
Original file line number Diff line number Diff line change
@@ -24,10 +24,10 @@ the installation root's `bin` folder.
include::description-install-root.adoc[]

There are multiple sources from which a crate can be installed. The default
location is crates.io but the `--git` and `--path` flags can change this
source. If the source contains more than one package (such as crates.io or a
git repository with multiple crates) the _CRATE_ argument is required to
indicate which crate should be installed.
location is crates.io but the `--git`, `--path`, and `registry` flags can
change this source. If the source contains more than one package (such as
crates.io or a git repository with multiple crates) the _CRATE_ argument is
required to indicate which crate should be installed.

Crates from crates.io can optionally specify the version they wish to install
via the `--version` flags, and similarly packages from git repositories can
@@ -48,7 +48,7 @@ continuous integration systems.

*--vers* _VERSION_::
*--version* _VERSION_::
Specify a version to install from crates.io.
Specify a version to install.

*--git* _URL_::
Git URL to install the specified crate from.
10 changes: 5 additions & 5 deletions src/doc/man/generated/cargo-install.html
Original file line number Diff line number Diff line change
@@ -45,10 +45,10 @@ <h2 id="cargo_install_description">DESCRIPTION</h2>
</div>
<div class="paragraph">
<p>There are multiple sources from which a crate can be installed. The default
location is crates.io but the <code>--git</code> and <code>--path</code> flags can change this
source. If the source contains more than one package (such as crates.io or a
git repository with multiple crates) the <em>CRATE</em> argument is required to
indicate which crate should be installed.</p>
location is crates.io but the <code>--git</code>, <code>--path</code>, and <code>registry</code> flags can
change this source. If the source contains more than one package (such as
crates.io or a git repository with multiple crates) the <em>CRATE</em> argument is
required to indicate which crate should be installed.</p>
</div>
<div class="paragraph">
<p>Crates from crates.io can optionally specify the version they wish to install
@@ -77,7 +77,7 @@ <h3 id="cargo_install_install_options">Install Options</h3>
<dt class="hdlist1"><strong>--vers</strong> <em>VERSION</em></dt>
<dt class="hdlist1"><strong>--version</strong> <em>VERSION</em></dt>
<dd>
<p>Specify a version to install from crates.io.</p>
<p>Specify a version to install.</p>
</dd>
<dt class="hdlist1"><strong>--git</strong> <em>URL</em></dt>
<dd>
14 changes: 7 additions & 7 deletions src/etc/man/cargo-install.1
Original file line number Diff line number Diff line change
@@ -2,12 +2,12 @@
.\" Title: cargo-install
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 1.5.8
.\" Date: 2019-01-23
.\" Date: 2019-03-31
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "CARGO\-INSTALL" "1" "2019-01-23" "\ \&" "\ \&"
.TH "CARGO\-INSTALL" "1" "2019-03-31" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
@@ -103,10 +103,10 @@ The installation root is determined, in order of precedence:
.RE
.sp
There are multiple sources from which a crate can be installed. The default
location is crates.io but the \fB\-\-git\fP and \fB\-\-path\fP flags can change this
source. If the source contains more than one package (such as crates.io or a
git repository with multiple crates) the \fICRATE\fP argument is required to
indicate which crate should be installed.
location is crates.io but the \fB\-\-git\fP, \fB\-\-path\fP, and \fBregistry\fP flags can
change this source. If the source contains more than one package (such as
crates.io or a git repository with multiple crates) the \fICRATE\fP argument is
required to indicate which crate should be installed.
.sp
Crates from crates.io can optionally specify the version they wish to install
via the \fB\-\-version\fP flags, and similarly packages from git repositories can
@@ -125,7 +125,7 @@ continuous integration systems.
.sp
\fB\-\-vers\fP \fIVERSION\fP, \fB\-\-version\fP \fIVERSION\fP
.RS 4
Specify a version to install from crates.io.
Specify a version to install.
.RE
.sp
\fB\-\-git\fP \fIURL\fP
2 changes: 1 addition & 1 deletion tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
@@ -620,7 +620,7 @@ Caused by:
.run();

for cmd in &[
"init", "install", "login", "owner", "publish", "search", "yank",
"init", "install foo", "login", "owner", "publish", "search", "yank",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I should have left a comment. install --registry now requires a package name (foo) and that validation is done before the --registry name validation.

] {
p.cargo(cmd)
.arg("--registry")