@@ -11,6 +11,7 @@ use std::fmt::Write;
1111
1212use super :: commands;
1313use super :: list_commands;
14+ use super :: user_defined_aliases;
1415use crate :: command_prelude:: * ;
1516use crate :: util:: is_rustup;
1617use cargo:: core:: shell:: ColorChoice ;
@@ -691,11 +692,13 @@ See '<cyan,bold>cargo help</> <cyan><<command>></>' for more information on a sp
691692 } ) )
692693 } ) . collect ( )
693694 } ) ) )
694- . add ( clap_complete:: engine:: SubcommandCandidates :: new ( || {
695- get_toolchains_from_rustup ( )
695+ . add ( clap_complete:: engine:: SubcommandCandidates :: new ( move || {
696+ let mut candidates = get_toolchains_from_rustup ( )
696697 . into_iter ( )
697698 . map ( |t| clap_complete:: CompletionCandidate :: new ( t) )
698- . collect ( )
699+ . collect :: < Vec < _ > > ( ) ;
700+ candidates. extend ( get_alias_candidates ( ) ) ;
701+ candidates
699702 } ) )
700703 . subcommands ( commands:: builtin ( ) )
701704}
@@ -717,6 +720,35 @@ fn get_toolchains_from_rustup() -> Vec<String> {
717720 stdout. lines ( ) . map ( |line| format ! ( "+{}" , line) ) . collect ( )
718721}
719722
723+ fn get_alias_candidates ( ) -> Vec < clap_complete:: CompletionCandidate > {
724+ if let Ok ( gctx) = new_gctx_for_completions ( ) {
725+ let alias_map = user_defined_aliases ( & gctx) ;
726+ return alias_map
727+ . iter ( )
728+ . map ( |( alias, cmd_info) | {
729+ let help_text = match cmd_info {
730+ CommandInfo :: Alias { target } => {
731+ let cmd_str = target
732+ . iter ( )
733+ . map ( String :: as_str)
734+ . collect :: < Vec < _ > > ( )
735+ . join ( " " ) ;
736+ format ! ( "alias for {}" , cmd_str)
737+ }
738+ CommandInfo :: BuiltIn { .. } => {
739+ unreachable ! ( "BuiltIn command shouldn't appear in alias map" )
740+ }
741+ CommandInfo :: External { .. } => {
742+ unreachable ! ( "External command shouldn't appear in alias map" )
743+ }
744+ } ;
745+ clap_complete:: CompletionCandidate :: new ( alias. clone ( ) ) . help ( Some ( help_text. into ( ) ) )
746+ } )
747+ . collect ( ) ;
748+ }
749+ Vec :: new ( )
750+ }
751+
720752#[ test]
721753fn verify_cli ( ) {
722754 let gctx = GlobalContext :: default ( ) . unwrap ( ) ;
0 commit comments