Auto merge of #10107 - hi-rustin:rustin-patch-install, r=ehuss

Add --message-format for install command

close https://github.com/rust-lang/cargo/issues/10104
This commit is contained in:
bors 2021-11-21 16:13:58 +00:00
commit df8cda0a12
6 changed files with 174 additions and 0 deletions

View File

@ -71,6 +71,7 @@ pub fn cli() -> App {
.requires("crate")
.conflicts_with_all(&["git", "path", "index"]),
)
.arg_message_format()
.after_help("Run `cargo help install` for more detailed information.\n")
}

View File

@ -185,6 +185,9 @@ See also the `--profile` option for choosing a specific profile by name.
{{#options}}
{{> options-display }}
{{> options-message-format }}
{{/options}}
{{> section-options-common }}

View File

@ -262,6 +262,34 @@ OPTIONS
May also be specified with the term.color config value
<https://doc.rust-lang.org/cargo/reference/config.html>.
--message-format fmt
The output format for diagnostic messages. Can be specified multiple
times and consists of comma-separated values. Valid values:
o human (default): Display in a human-readable text format.
Conflicts with short and json.
o short: Emit shorter, human-readable text messages. Conflicts with
human and json.
o json: Emit JSON messages to stdout. See the reference
<https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
for more details. Conflicts with human and short.
o json-diagnostic-short: Ensure the rendered field of JSON messages
contains the "short" rendering from rustc. Cannot be used with
human or short.
o json-diagnostic-rendered-ansi: Ensure the rendered field of JSON
messages contains embedded ANSI color codes for respecting
rustc's default color scheme. Cannot be used with human or short.
o json-render-diagnostics: Instruct Cargo to not include rustc
diagnostics in in JSON messages printed, but instead Cargo itself
should render the JSON diagnostics coming from rustc. Cargo's own
JSON diagnostics and others coming from rustc are still emitted.
Cannot be used with human or short.
Common Options
+toolchain
If Cargo has been installed with rustup, and the first argument to

View File

@ -307,6 +307,31 @@ terminal.</li>
<a href="../reference/config.html">config value</a>.</dd>
<dt class="option-term" id="option-cargo-install---message-format"><a class="option-anchor" href="#option-cargo-install---message-format"></a><code>--message-format</code> <em>fmt</em></dt>
<dd class="option-desc">The output format for diagnostic messages. Can be specified multiple times
and consists of comma-separated values. Valid values:</p>
<ul>
<li><code>human</code> (default): Display in a human-readable text format. Conflicts with
<code>short</code> and <code>json</code>.</li>
<li><code>short</code>: Emit shorter, human-readable text messages. Conflicts with <code>human</code>
and <code>json</code>.</li>
<li><code>json</code>: Emit JSON messages to stdout. See
<a href="../reference/external-tools.html#json-messages">the reference</a>
for more details. Conflicts with <code>human</code> and <code>short</code>.</li>
<li><code>json-diagnostic-short</code>: Ensure the <code>rendered</code> field of JSON messages contains
the &quot;short&quot; rendering from rustc. Cannot be used with <code>human</code> or <code>short</code>.</li>
<li><code>json-diagnostic-rendered-ansi</code>: Ensure the <code>rendered</code> field of JSON messages
contains embedded ANSI color codes for respecting rustc's default color
scheme. Cannot be used with <code>human</code> or <code>short</code>.</li>
<li><code>json-render-diagnostics</code>: Instruct Cargo to not include rustc diagnostics in
in JSON messages printed, but instead Cargo itself should render the
JSON diagnostics coming from rustc. Cargo's own JSON diagnostics and others
coming from rustc are still emitted. Cannot be used with <code>human</code> or <code>short</code>.</li>
</ul></dd>
</dl>
### Common Options

View File

@ -342,6 +342,46 @@ terminal.
May also be specified with the \fBterm.color\fR
\fIconfig value\fR <https://doc.rust\-lang.org/cargo/reference/config.html>\&.
.RE
.sp
\fB\-\-message\-format\fR \fIfmt\fR
.RS 4
The output format for diagnostic messages. Can be specified multiple times
and consists of comma\-separated values. Valid values:
.sp
.RS 4
\h'-04'\(bu\h'+02'\fBhuman\fR (default): Display in a human\-readable text format. Conflicts with
\fBshort\fR and \fBjson\fR\&.
.RE
.sp
.RS 4
\h'-04'\(bu\h'+02'\fBshort\fR: Emit shorter, human\-readable text messages. Conflicts with \fBhuman\fR
and \fBjson\fR\&.
.RE
.sp
.RS 4
\h'-04'\(bu\h'+02'\fBjson\fR: Emit JSON messages to stdout. See
\fIthe reference\fR <https://doc.rust\-lang.org/cargo/reference/external\-tools.html#json\-messages>
for more details. Conflicts with \fBhuman\fR and \fBshort\fR\&.
.RE
.sp
.RS 4
\h'-04'\(bu\h'+02'\fBjson\-diagnostic\-short\fR: Ensure the \fBrendered\fR field of JSON messages contains
the "short" rendering from rustc. Cannot be used with \fBhuman\fR or \fBshort\fR\&.
.RE
.sp
.RS 4
\h'-04'\(bu\h'+02'\fBjson\-diagnostic\-rendered\-ansi\fR: Ensure the \fBrendered\fR field of JSON messages
contains embedded ANSI color codes for respecting rustc's default color
scheme. Cannot be used with \fBhuman\fR or \fBshort\fR\&.
.RE
.sp
.RS 4
\h'-04'\(bu\h'+02'\fBjson\-render\-diagnostics\fR: Instruct Cargo to not include rustc diagnostics in
in JSON messages printed, but instead Cargo itself should render the
JSON diagnostics coming from rustc. Cargo's own JSON diagnostics and others
coming from rustc are still emitted. Cannot be used with \fBhuman\fR or \fBshort\fR\&.
.RE
.RE
.SS "Common Options"
.sp
\fB+\fR\fItoolchain\fR

View File

@ -54,6 +54,83 @@ fn simple() {
assert_has_not_installed_exe(cargo_home(), "foo");
}
#[cargo_test]
fn simple_with_message_format() {
pkg("foo", "0.0.1");
cargo_process("install foo --message-format=json")
.with_stderr(
"\
[UPDATING] `[..]` index
[DOWNLOADING] crates ...
[DOWNLOADED] foo v0.0.1 (registry [..])
[INSTALLING] foo v0.0.1
[COMPILING] foo v0.0.1
[FINISHED] release [optimized] target(s) in [..]
[INSTALLING] [CWD]/home/.cargo/bin/foo[EXE]
[INSTALLED] package `foo v0.0.1` (executable `foo[EXE]`)
[WARNING] be sure to add `[..]` to your PATH to be able to run the installed binaries
",
)
.with_json(
r#"
{
"reason": "compiler-artifact",
"package_id": "foo 0.0.1 ([..])",
"manifest_path": "[..]",
"target": {
"kind": [
"lib"
],
"crate_types": [
"lib"
],
"name": "foo",
"src_path": "[..]/foo-0.0.1/src/lib.rs",
"edition": "2015",
"doc": true,
"doctest": true,
"test": true
},
"profile": "{...}",
"features": [],
"filenames": "{...}",
"executable": null,
"fresh": false
}
{
"reason": "compiler-artifact",
"package_id": "foo 0.0.1 ([..])",
"manifest_path": "[..]",
"target": {
"kind": [
"bin"
],
"crate_types": [
"bin"
],
"name": "foo",
"src_path": "[..]/foo-0.0.1/src/main.rs",
"edition": "2015",
"doc": true,
"doctest": false,
"test": true
},
"profile": "{...}",
"features": [],
"filenames": "{...}",
"executable": "[..]",
"fresh": false
}
{"reason":"build-finished","success":true}
"#,
)
.run();
assert_has_installed_exe(cargo_home(), "foo");
}
#[cargo_test]
fn with_index() {
pkg("foo", "0.0.1");