File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -690,10 +690,39 @@ See '<cyan,bold>cargo help</> <cyan><<command>></>' for more information on a sp
690690 help. into ( )
691691 } ) )
692692 } ) . collect ( )
693+ } ) ) )
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
702+ . into_iter ( )
703+ . filter ( |t| OsStr :: new ( t) . as_encoded_bytes ( ) . starts_with ( partial. as_encoded_bytes ( ) ) )
704+ . map ( |t| clap_complete:: CompletionCandidate :: new ( t) )
705+ . collect ( )
693706 } ) ) )
694707 . subcommands ( commands:: builtin ( ) )
695708}
696709
710+ fn get_toolchains_from_rustup ( ) -> Vec < String > {
711+ let output = std:: process:: Command :: new ( "rustup" )
712+ . arg ( "toolchain" )
713+ . arg ( "list" )
714+ . output ( )
715+ . unwrap ( ) ;
716+
717+ if !output. status . success ( ) {
718+ return vec ! [ ] ;
719+ }
720+
721+ let stdout = String :: from_utf8 ( output. stdout ) . unwrap ( ) ;
722+
723+ stdout. lines ( ) . map ( |line| format ! ( "+{}" , line) ) . collect ( )
724+ }
725+
697726#[ test]
698727fn verify_cli ( ) {
699728 let gctx = GlobalContext :: default ( ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments