@@ -30,9 +30,6 @@ pub fn main(config: &mut LazyConfig) -> CliResult {
30
30
// the [alias] table).
31
31
let config = config. get_mut ( ) ;
32
32
33
- // Global args need to be extracted before expanding aliases because the
34
- // clap code for extracting a subcommand discards global options
35
- // (appearing before the subcommand).
36
33
let ( expanded_args, global_args) = expand_aliases ( config, args, vec ! [ ] ) ?;
37
34
38
35
if expanded_args
@@ -222,16 +219,30 @@ fn add_ssl(version_string: &mut String) {
222
219
}
223
220
}
224
221
222
+ /// Expands aliases recursively to collect all the command line arguments.
223
+ ///
224
+ /// [`GlobalArgs`] need to be extracted before expanding aliases because the
225
+ /// clap code for extracting a subcommand discards global options
226
+ /// (appearing before the subcommand).
225
227
fn expand_aliases (
226
228
config : & mut Config ,
227
229
args : ArgMatches ,
228
230
mut already_expanded : Vec < String > ,
229
231
) -> Result < ( ArgMatches , GlobalArgs ) , CliError > {
230
232
if let Some ( ( cmd, args) ) = args. subcommand ( ) {
231
- match (
232
- commands:: builtin_exec ( cmd) ,
233
- super :: aliased_command ( config, cmd) ?,
234
- ) {
233
+ let exec = commands:: builtin_exec ( cmd) ;
234
+ let aliased_cmd = super :: aliased_command ( config, cmd) . or_else ( |e| {
235
+ // HACK: `cargo version` must always work even with malformed configs.
236
+ // Here we treat the error as the aliased command not found,
237
+ // so it falls back to call builtin `cargo version`
238
+ if cmd == "version" {
239
+ Ok ( None )
240
+ } else {
241
+ Err ( e)
242
+ }
243
+ } ) ?;
244
+
245
+ match ( exec, aliased_cmd) {
235
246
( Some ( _) , Some ( _) ) => {
236
247
// User alias conflicts with a built-in subcommand
237
248
config. shell ( ) . warn ( format ! (
0 commit comments