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/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 . + --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 + + 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. config value. + +
--message-format fmt
+
The output format for diagnostic messages. Can be specified multiple times +and consists of comma-separated values. Valid values:

+
    +
  • human (default): Display in a human-readable text format. Conflicts with +short and json.
  • +
  • short: Emit shorter, human-readable text messages. Conflicts with human +and json.
  • +
  • json: Emit JSON messages to stdout. See +the reference +for more details. Conflicts with human and short.
  • +
  • json-diagnostic-short: Ensure the rendered field of JSON messages contains +the "short" rendering from rustc. Cannot be used with human or short.
  • +
  • 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.
  • +
  • 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 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 \&. .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 +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 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");