Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d929d47

Browse files
committed
feat: vcs, color, and message format native completion
1 parent 68c26f6 commit d929d47

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

src/bin/cargo/cli.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,14 @@ See '<cyan,bold>cargo help</> <cyan><<command>></>' for more information on a sp
635635
.arg(
636636
opt("color", "Coloring: auto, always, never")
637637
.value_name("WHEN")
638-
.global(true),
638+
.global(true)
639+
.add(clap_complete::ArgValueCandidates::new(|| {
640+
vec![
641+
clap_complete::CompletionCandidate::new("auto"),
642+
clap_complete::CompletionCandidate::new("always"),
643+
clap_complete::CompletionCandidate::new("never"),
644+
]
645+
})),
639646
)
640647
.arg(
641648
Arg::new("directory")

src/bin/cargo/commands/config.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ pub fn cli() -> Command {
1616
.arg(
1717
opt("format", "Display format")
1818
.value_parser(cargo_config::ConfigFormat::POSSIBLE_VALUES)
19-
.default_value("toml"),
19+
.default_value("toml")
20+
.add(clap_complete::ArgValueCandidates::new(|| {
21+
cargo_config::ConfigFormat::POSSIBLE_VALUES
22+
.iter()
23+
.map(|&value| clap_complete::CompletionCandidate::new(value))
24+
.collect()
25+
})),
2026
)
2127
.arg(flag(
2228
"show-origin",
@@ -25,7 +31,13 @@ pub fn cli() -> Command {
2531
.arg(
2632
opt("merged", "Whether or not to merge config values")
2733
.value_parser(["yes", "no"])
28-
.default_value("yes"),
34+
.default_value("yes")
35+
.add(clap_complete::ArgValueCandidates::new(|| {
36+
vec![
37+
clap_complete::CompletionCandidate::new("yes"),
38+
clap_complete::CompletionCandidate::new("no"),
39+
]
40+
})),
2941
),
3042
)
3143
}

src/bin/cargo/commands/locate_project.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ pub fn cli() -> Command {
1212
"message-format",
1313
"Output representation [possible values: json, plain]",
1414
)
15-
.value_name("FMT"),
15+
.value_name("FMT")
16+
.add(clap_complete::ArgValueCandidates::new(|| {
17+
vec![
18+
clap_complete::CompletionCandidate::new("json"),
19+
clap_complete::CompletionCandidate::new("plain"),
20+
]
21+
})),
1622
)
1723
.arg_silent_suggestion()
1824
.arg_manifest_path()

src/cargo/util/command_prelude.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,18 @@ 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(multi_opt("message-format", "FMT", "Error format").add(
365+
clap_complete::ArgValueCandidates::new(|| {
366+
vec![
367+
clap_complete::CompletionCandidate::new("human"),
368+
clap_complete::CompletionCandidate::new("short"),
369+
clap_complete::CompletionCandidate::new("json"),
370+
clap_complete::CompletionCandidate::new("json-diagnostic-short"),
371+
clap_complete::CompletionCandidate::new("json-diagnostic-rendered-ansi"),
372+
clap_complete::CompletionCandidate::new("json-render-diagnostics"),
373+
]
374+
}),
375+
))
365376
}
366377

367378
fn arg_build_plan(self) -> Self {
@@ -387,7 +398,16 @@ pub trait CommandExt: Sized {
387398
a global configuration.",
388399
)
389400
.value_name("VCS")
390-
.value_parser(["git", "hg", "pijul", "fossil", "none"]),
401+
.value_parser(["git", "hg", "pijul", "fossil", "none"])
402+
.add(clap_complete::ArgValueCandidates::new(|| {
403+
vec![
404+
clap_complete::CompletionCandidate::new("git"),
405+
clap_complete::CompletionCandidate::new("hg"),
406+
clap_complete::CompletionCandidate::new("pijul"),
407+
clap_complete::CompletionCandidate::new("fossil"),
408+
clap_complete::CompletionCandidate::new("none"),
409+
]
410+
})),
391411
)
392412
._arg(
393413
flag("bin", "Use a binary (application) template [default]")

0 commit comments

Comments
 (0)