From 6351472a80f0e86bbdf17618a65019d2490cce95 Mon Sep 17 00:00:00 2001 From: hi-rustin <rustin.liu@gmail.com> Date: Sun, 21 Nov 2021 12:16:50 +0800 Subject: [PATCH 1/2] Add --message-format for install Signed-off-by: hi-rustin <rustin.liu@gmail.com> --- src/bin/cargo/commands/install.rs | 1 + tests/testsuite/install.rs | 77 +++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs index 56ea10c39e9..798a08d8d57 100644 --- a/src/bin/cargo/commands/install.rs +++ b/src/bin/cargo/commands/install.rs @@ -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") } diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index abdd861f837..b28b3743c23 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -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"); From 890b0e888b07300c62529dcdd8439b82784cf73b Mon Sep 17 00:00:00 2001 From: hi-rustin <rustin.liu@gmail.com> Date: Sun, 21 Nov 2021 12:22:02 +0800 Subject: [PATCH 2/2] Update install doc Signed-off-by: hi-rustin <rustin.liu@gmail.com> --- src/doc/man/cargo-install.md | 3 ++ src/doc/man/generated_txt/cargo-install.txt | 28 +++++++++++++++ src/doc/src/commands/cargo-install.md | 25 +++++++++++++ src/etc/man/cargo-install.1 | 40 +++++++++++++++++++++ 4 files changed, 96 insertions(+) diff --git a/src/doc/man/cargo-install.md b/src/doc/man/cargo-install.md index bea6ec37c4f..28d7c6ab16e 100644 --- a/src/doc/man/cargo-install.md +++ b/src/doc/man/cargo-install.md @@ -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 }} diff --git a/src/doc/man/generated_txt/cargo-install.txt b/src/doc/man/generated_txt/cargo-install.txt index e2660e32d0d..7774a6c6139 100644 --- a/src/doc/man/generated_txt/cargo-install.txt +++ b/src/doc/man/generated_txt/cargo-install.txt @@ -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 diff --git a/src/doc/src/commands/cargo-install.md b/src/doc/src/commands/cargo-install.md index 01cee96d516..70b9591ac67 100644 --- a/src/doc/src/commands/cargo-install.md +++ b/src/doc/src/commands/cargo-install.md @@ -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 "short" 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 diff --git a/src/etc/man/cargo-install.1 b/src/etc/man/cargo-install.1 index ed719a0e0df..babd1c81f3b 100644 --- a/src/etc/man/cargo-install.1 +++ b/src/etc/man/cargo-install.1 @@ -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