@@ -520,10 +520,6 @@ void CommandInterpreter::Initialize() {
520
520
521
521
cmd_obj_sp = GetCommandSPExact (" scripting run" );
522
522
if (cmd_obj_sp) {
523
- AddAlias (" sc" , cmd_obj_sp);
524
- AddAlias (" scr" , cmd_obj_sp);
525
- AddAlias (" scri" , cmd_obj_sp);
526
- AddAlias (" scrip" , cmd_obj_sp);
527
523
AddAlias (" script" , cmd_obj_sp);
528
524
}
529
525
@@ -1302,6 +1298,39 @@ CommandObject *CommandInterpreter::GetUserCommandObject(
1302
1298
return {};
1303
1299
}
1304
1300
1301
+ CommandObject *CommandInterpreter::GetAliasCommandObject (
1302
+ llvm::StringRef cmd, StringList *matches, StringList *descriptions) const {
1303
+ auto find_exact =
1304
+ [&](const CommandObject::CommandMap &map) -> CommandObject * {
1305
+ auto found_elem = map.find (cmd.str ());
1306
+ if (found_elem == map.end ())
1307
+ return (CommandObject *)nullptr ;
1308
+ CommandObject *exact_cmd = found_elem->second .get ();
1309
+ if (!exact_cmd)
1310
+ return nullptr ;
1311
+
1312
+ if (matches)
1313
+ matches->AppendString (exact_cmd->GetCommandName ());
1314
+
1315
+ if (descriptions)
1316
+ descriptions->AppendString (exact_cmd->GetHelp ());
1317
+
1318
+ return exact_cmd;
1319
+ return nullptr ;
1320
+ };
1321
+
1322
+ CommandObject *exact_cmd = find_exact (GetAliases ());
1323
+ if (exact_cmd)
1324
+ return exact_cmd;
1325
+
1326
+ // We didn't have an exact command, so now look for partial matches.
1327
+ StringList tmp_list;
1328
+ StringList *matches_ptr = matches ? matches : &tmp_list;
1329
+ AddNamesMatchingPartialString (GetAliases (), cmd, *matches_ptr);
1330
+
1331
+ return {};
1332
+ }
1333
+
1305
1334
bool CommandInterpreter::CommandExists (llvm::StringRef cmd) const {
1306
1335
return m_command_dict.find (std::string (cmd)) != m_command_dict.end ();
1307
1336
}
@@ -3421,6 +3450,19 @@ CommandInterpreter::ResolveCommandImpl(std::string &command_line,
3421
3450
std::string next_word;
3422
3451
StringList matches;
3423
3452
bool done = false ;
3453
+
3454
+ auto build_alias_cmd = [&](std::string &full_name) {
3455
+ revised_command_line.Clear ();
3456
+ matches.Clear ();
3457
+ std::string alias_result;
3458
+ cmd_obj =
3459
+ BuildAliasResult (full_name, scratch_command, alias_result, result);
3460
+ revised_command_line.Printf (" %s" , alias_result.c_str ());
3461
+ if (cmd_obj) {
3462
+ wants_raw_input = cmd_obj->WantsRawCommandString ();
3463
+ }
3464
+ };
3465
+
3424
3466
while (!done) {
3425
3467
char quote_char = ' \0 ' ;
3426
3468
std::string suffix;
@@ -3432,14 +3474,7 @@ CommandInterpreter::ResolveCommandImpl(std::string &command_line,
3432
3474
bool is_real_command =
3433
3475
(!is_alias) || (cmd_obj != nullptr && !cmd_obj->IsAlias ());
3434
3476
if (!is_real_command) {
3435
- matches.Clear ();
3436
- std::string alias_result;
3437
- cmd_obj =
3438
- BuildAliasResult (full_name, scratch_command, alias_result, result);
3439
- revised_command_line.Printf (" %s" , alias_result.c_str ());
3440
- if (cmd_obj) {
3441
- wants_raw_input = cmd_obj->WantsRawCommandString ();
3442
- }
3477
+ build_alias_cmd (full_name);
3443
3478
} else {
3444
3479
if (cmd_obj) {
3445
3480
llvm::StringRef cmd_name = cmd_obj->GetCommandName ();
@@ -3486,21 +3521,32 @@ CommandInterpreter::ResolveCommandImpl(std::string &command_line,
3486
3521
if (cmd_obj == nullptr ) {
3487
3522
const size_t num_matches = matches.GetSize ();
3488
3523
if (matches.GetSize () > 1 ) {
3489
- StreamString error_msg;
3490
- error_msg.Printf (" Ambiguous command '%s'. Possible matches:\n " ,
3491
- next_word.c_str ());
3524
+ StringList alias_matches;
3525
+ GetAliasCommandObject (next_word, &alias_matches);
3526
+
3527
+ if (alias_matches.GetSize () == 1 ) {
3528
+ std::string full_name;
3529
+ GetAliasFullName (alias_matches.GetStringAtIndex (0 ), full_name);
3530
+ build_alias_cmd (full_name);
3531
+ done = static_cast <bool >(cmd_obj);
3532
+ } else {
3533
+ StreamString error_msg;
3534
+ error_msg.Printf (" Ambiguous command '%s'. Possible matches:\n " ,
3535
+ next_word.c_str ());
3492
3536
3493
- for (uint32_t i = 0 ; i < num_matches; ++i) {
3494
- error_msg.Printf (" \t %s\n " , matches.GetStringAtIndex (i));
3537
+ for (uint32_t i = 0 ; i < num_matches; ++i) {
3538
+ error_msg.Printf (" \t %s\n " , matches.GetStringAtIndex (i));
3539
+ }
3540
+ result.AppendRawError (error_msg.GetString ());
3495
3541
}
3496
- result.AppendRawError (error_msg.GetString ());
3497
3542
} else {
3498
3543
// We didn't have only one match, otherwise we wouldn't get here.
3499
3544
lldbassert (num_matches == 0 );
3500
3545
result.AppendErrorWithFormat (" '%s' is not a valid command.\n " ,
3501
3546
next_word.c_str ());
3502
3547
}
3503
- return nullptr ;
3548
+ if (!done)
3549
+ return nullptr ;
3504
3550
}
3505
3551
3506
3552
if (cmd_obj->IsMultiwordObject ()) {
0 commit comments