@@ -527,10 +527,6 @@ void CommandInterpreter::Initialize() {
527
527
528
528
cmd_obj_sp = GetCommandSPExact (" scripting run" );
529
529
if (cmd_obj_sp) {
530
- AddAlias (" sc" , cmd_obj_sp);
531
- AddAlias (" scr" , cmd_obj_sp);
532
- AddAlias (" scri" , cmd_obj_sp);
533
- AddAlias (" scrip" , cmd_obj_sp);
534
530
AddAlias (" script" , cmd_obj_sp);
535
531
}
536
532
@@ -1315,6 +1311,39 @@ CommandObject *CommandInterpreter::GetUserCommandObject(
1315
1311
return {};
1316
1312
}
1317
1313
1314
+ CommandObject *CommandInterpreter::GetAliasCommandObject (
1315
+ llvm::StringRef cmd, StringList *matches, StringList *descriptions) const {
1316
+ auto find_exact =
1317
+ [&](const CommandObject::CommandMap &map) -> CommandObject * {
1318
+ auto found_elem = map.find (cmd.str ());
1319
+ if (found_elem == map.end ())
1320
+ return (CommandObject *)nullptr ;
1321
+ CommandObject *exact_cmd = found_elem->second .get ();
1322
+ if (!exact_cmd)
1323
+ return nullptr ;
1324
+
1325
+ if (matches)
1326
+ matches->AppendString (exact_cmd->GetCommandName ());
1327
+
1328
+ if (descriptions)
1329
+ descriptions->AppendString (exact_cmd->GetHelp ());
1330
+
1331
+ return exact_cmd;
1332
+ return nullptr ;
1333
+ };
1334
+
1335
+ CommandObject *exact_cmd = find_exact (GetAliases ());
1336
+ if (exact_cmd)
1337
+ return exact_cmd;
1338
+
1339
+ // We didn't have an exact command, so now look for partial matches.
1340
+ StringList tmp_list;
1341
+ StringList *matches_ptr = matches ? matches : &tmp_list;
1342
+ AddNamesMatchingPartialString (GetAliases (), cmd, *matches_ptr);
1343
+
1344
+ return {};
1345
+ }
1346
+
1318
1347
bool CommandInterpreter::CommandExists (llvm::StringRef cmd) const {
1319
1348
return m_command_dict.find (std::string (cmd)) != m_command_dict.end ();
1320
1349
}
@@ -3434,6 +3463,19 @@ CommandInterpreter::ResolveCommandImpl(std::string &command_line,
3434
3463
std::string next_word;
3435
3464
StringList matches;
3436
3465
bool done = false ;
3466
+
3467
+ auto build_alias_cmd = [&](std::string &full_name) {
3468
+ revised_command_line.Clear ();
3469
+ matches.Clear ();
3470
+ std::string alias_result;
3471
+ cmd_obj =
3472
+ BuildAliasResult (full_name, scratch_command, alias_result, result);
3473
+ revised_command_line.Printf (" %s" , alias_result.c_str ());
3474
+ if (cmd_obj) {
3475
+ wants_raw_input = cmd_obj->WantsRawCommandString ();
3476
+ }
3477
+ };
3478
+
3437
3479
while (!done) {
3438
3480
char quote_char = ' \0 ' ;
3439
3481
std::string suffix;
@@ -3445,14 +3487,7 @@ CommandInterpreter::ResolveCommandImpl(std::string &command_line,
3445
3487
bool is_real_command =
3446
3488
(!is_alias) || (cmd_obj != nullptr && !cmd_obj->IsAlias ());
3447
3489
if (!is_real_command) {
3448
- matches.Clear ();
3449
- std::string alias_result;
3450
- cmd_obj =
3451
- BuildAliasResult (full_name, scratch_command, alias_result, result);
3452
- revised_command_line.Printf (" %s" , alias_result.c_str ());
3453
- if (cmd_obj) {
3454
- wants_raw_input = cmd_obj->WantsRawCommandString ();
3455
- }
3490
+ build_alias_cmd (full_name);
3456
3491
} else {
3457
3492
if (cmd_obj) {
3458
3493
llvm::StringRef cmd_name = cmd_obj->GetCommandName ();
@@ -3499,21 +3534,32 @@ CommandInterpreter::ResolveCommandImpl(std::string &command_line,
3499
3534
if (cmd_obj == nullptr ) {
3500
3535
const size_t num_matches = matches.GetSize ();
3501
3536
if (matches.GetSize () > 1 ) {
3502
- StreamString error_msg;
3503
- error_msg.Printf (" Ambiguous command '%s'. Possible matches:\n " ,
3504
- next_word.c_str ());
3537
+ StringList alias_matches;
3538
+ GetAliasCommandObject (next_word, &alias_matches);
3539
+
3540
+ if (alias_matches.GetSize () == 1 ) {
3541
+ std::string full_name;
3542
+ GetAliasFullName (alias_matches.GetStringAtIndex (0 ), full_name);
3543
+ build_alias_cmd (full_name);
3544
+ done = static_cast <bool >(cmd_obj);
3545
+ } else {
3546
+ StreamString error_msg;
3547
+ error_msg.Printf (" Ambiguous command '%s'. Possible matches:\n " ,
3548
+ next_word.c_str ());
3505
3549
3506
- for (uint32_t i = 0 ; i < num_matches; ++i) {
3507
- error_msg.Printf (" \t %s\n " , matches.GetStringAtIndex (i));
3550
+ for (uint32_t i = 0 ; i < num_matches; ++i) {
3551
+ error_msg.Printf (" \t %s\n " , matches.GetStringAtIndex (i));
3552
+ }
3553
+ result.AppendRawError (error_msg.GetString ());
3508
3554
}
3509
- result.AppendRawError (error_msg.GetString ());
3510
3555
} else {
3511
3556
// We didn't have only one match, otherwise we wouldn't get here.
3512
3557
lldbassert (num_matches == 0 );
3513
3558
result.AppendErrorWithFormat (" '%s' is not a valid command.\n " ,
3514
3559
next_word.c_str ());
3515
3560
}
3516
- return nullptr ;
3561
+ if (!done)
3562
+ return nullptr ;
3517
3563
}
3518
3564
3519
3565
if (cmd_obj->IsMultiwordObject ()) {
0 commit comments