Skip to content

Commit 7b07ca5

Browse files
committed
use subcommand candidate
1 parent dbb5254 commit 7b07ca5

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/bin/cargo/cli.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -691,36 +691,33 @@ See '<cyan,bold>cargo help</> <cyan><<command>></>' for more information on a sp
691691
}))
692692
}).collect()
693693
})))
694-
.arg( Arg::new("toolchain")
695-
.help("Specifies the toolchain to use for this command")
696-
.value_name("TOOLCHAIN")
697-
.action(ArgAction::Set)
698-
.add(clap_complete::engine::ArgValueCompleter::new(|partial: &OsStr| {
699-
let toolchains = get_toolchains_from_rustup();
700-
701-
toolchains
694+
.add(clap_complete::engine::SubcommandCandidates::new(|| {
695+
get_toolchains_from_rustup()
702696
.into_iter()
703-
.filter(|t| OsStr::new(t).as_encoded_bytes().starts_with(partial.as_encoded_bytes()))
704697
.map(|t| clap_complete::CompletionCandidate::new(t))
705698
.collect()
706-
})))
699+
}))
707700
.subcommands(commands::builtin())
708701
}
709702

710703
fn get_toolchains_from_rustup() -> Vec<String> {
711704
let output = std::process::Command::new("rustup")
712705
.arg("toolchain")
713706
.arg("list")
707+
.arg("-q")
714708
.output()
715709
.unwrap();
716-
710+
717711
if !output.status.success() {
718712
return vec![];
719713
}
720714

721715
let stdout = String::from_utf8(output.stdout).unwrap();
722716

723-
stdout.lines().map(|line| format!("+{}", line)).collect()
717+
stdout
718+
.lines()
719+
.map(|line| format!("+{}", line))
720+
.collect()
724721
}
725722

726723
#[test]

0 commit comments

Comments
 (0)