@@ -11,6 +11,7 @@ use std::fmt::Write;
11
11
12
12
use super :: commands;
13
13
use super :: list_commands;
14
+ use super :: user_defined_aliases;
14
15
use crate :: command_prelude:: * ;
15
16
use crate :: util:: is_rustup;
16
17
use cargo:: core:: shell:: ColorChoice ;
@@ -691,11 +692,13 @@ See '<cyan,bold>cargo help</> <cyan><<command>></>' for more information on a sp
691
692
} ) )
692
693
} ) . collect ( )
693
694
} ) ) )
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 ( )
696
697
. into_iter ( )
697
698
. map ( |t| clap_complete:: CompletionCandidate :: new ( t) )
698
- . collect ( )
699
+ . collect :: < Vec < _ > > ( ) ;
700
+ candidates. extend ( get_alias_candidates ( ) ) ;
701
+ candidates
699
702
} ) )
700
703
. subcommands ( commands:: builtin ( ) )
701
704
}
@@ -717,6 +720,35 @@ fn get_toolchains_from_rustup() -> Vec<String> {
717
720
stdout. lines ( ) . map ( |line| format ! ( "+{}" , line) ) . collect ( )
718
721
}
719
722
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
+
720
752
#[ test]
721
753
fn verify_cli ( ) {
722
754
let gctx = GlobalContext :: default ( ) . unwrap ( ) ;
0 commit comments