Skip to content

Commit 8364f7b

Browse files
authored
feat: vcs, color, and message format native completion (#15322)
### What does this PR try to resolve? Related to rust-lang/cargo#14520 This PR introduces auto-completion for following options: 1. `--color` option with values: auto, always, never 2. `--vcs` option with values: git, hg, pijul, fossil, none 3. `--message-format` option with values: human, short, json, json-diagnostic-short, json-diagnostic-rendered Take `--color` as an example, when a user types ` cargo build --color <TAB>`the system will automatically suggest auto, always, never ### How should we test and review this PR? To verify this feature, follow these steps: 1. In the terminal, type `cargo build --color <TAB>` or `cargo new my_project --vcs <TAB>` or `cargo check --message-format <TAB>` 2. Press the TAB key. 3. You should see option suggestions https://github.com/user-attachments/assets/0cf12785-fdc0-4fb1-84b5-715c29a95e0e
2 parents c746f16 + 3ea0e6b commit 8364f7b

File tree

44 files changed

+670
-607
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+670
-607
lines changed

src/bin/cargo/cli.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -633,9 +633,11 @@ See '<cyan,bold>cargo help</> <cyan><<command>></>' for more information on a sp
633633
)
634634
.arg(flag("quiet", "Do not print cargo log messages").short('q').global(true))
635635
.arg(
636-
opt("color", "Coloring: auto, always, never")
636+
opt("color", "Coloring")
637637
.value_name("WHEN")
638-
.global(true),
638+
.global(true)
639+
.value_parser(["auto", "always", "never"])
640+
.ignore_case(true),
639641
)
640642
.arg(
641643
Arg::new("directory")

src/bin/cargo/commands/locate_project.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ pub fn cli() -> Command {
88
.about("Print a JSON representation of a Cargo.toml file's location")
99
.arg(flag("workspace", "Locate Cargo.toml of the workspace root"))
1010
.arg(
11-
opt(
12-
"message-format",
13-
"Output representation [possible values: json, plain]",
14-
)
15-
.value_name("FMT"),
11+
opt("message-format", "Output representation")
12+
.value_name("FMT")
13+
.value_parser(["json", "plain"])
14+
.ignore_case(true),
1615
)
1716
.arg_silent_suggestion()
1817
.arg_manifest_path()

src/cargo/util/command_prelude.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,19 @@ pub trait CommandExt: Sized {
361361
}
362362

363363
fn arg_message_format(self) -> Self {
364-
self._arg(multi_opt("message-format", "FMT", "Error format"))
364+
self._arg(
365+
multi_opt("message-format", "FMT", "Error format")
366+
.value_parser([
367+
"human",
368+
"short",
369+
"json",
370+
"json-diagnostic-short",
371+
"json-diagnostic-rendered-ansi",
372+
"json-render-diagnostics",
373+
])
374+
.value_delimiter(',')
375+
.ignore_case(true),
376+
)
365377
}
366378

367379
fn arg_build_plan(self) -> Self {

tests/testsuite/build.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -4066,9 +4066,12 @@ fn wrong_message_format_option() {
40664066
.build();
40674067

40684068
p.cargo("build --message-format XML")
4069-
.with_status(101)
4069+
.with_status(1)
40704070
.with_stderr_data(str![[r#"
4071-
[ERROR] invalid message format specifier: `xml`
4071+
[ERROR] invalid value 'XML' for '--message-format <FMT>'
4072+
[possible values: human, short, json, json-diagnostic-short, json-diagnostic-rendered-ansi, json-render-diagnostics]
4073+
4074+
For more information, try '--help'.
40724075
40734076
"#]])
40744077
.run();

tests/testsuite/cargo/help/stdout.term.svg

+1-1
Loading

tests/testsuite/cargo_add/help/stdout.term.svg

+84-80
Loading

tests/testsuite/cargo_bench/help/stdout.term.svg

+54-50
Loading

tests/testsuite/cargo_build/help/stdout.term.svg

+58-54
Loading

tests/testsuite/cargo_check/help/stdout.term.svg

+56-52
Loading

tests/testsuite/cargo_clean/help/stdout.term.svg

+1-1
Loading

tests/testsuite/cargo_config/help/stdout.term.svg

+1-1
Loading

0 commit comments

Comments
 (0)