File tree 1 file changed +29
-0
lines changed
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
690
690
help. into ( )
691
691
} ) )
692
692
} ) . 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 ( )
693
706
} ) ) )
694
707
. subcommands ( commands:: builtin ( ) )
695
708
}
696
709
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
+
697
726
#[ test]
698
727
fn verify_cli ( ) {
699
728
let gctx = GlobalContext :: default ( ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments