Skip to content

Commit

Permalink
Auto merge of #10107 - hi-rustin:rustin-patch-install, r=ehuss
Browse files Browse the repository at this point in the history
Add --message-format for install command

close #10104
  • Loading branch information
bors committed Nov 21, 2021
2 parents 934bc61 + 890b0e8 commit df8cda0
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/bin/cargo/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
3 changes: 3 additions & 0 deletions src/doc/man/cargo-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
28 changes: 28 additions & 0 deletions src/doc/man/generated_txt/cargo-install.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions src/doc/src/commands/cargo-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions src/etc/man/cargo-install.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
77 changes: 77 additions & 0 deletions tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit df8cda0

Please sign in to comment.