@@ -527,10 +527,6 @@ void CommandInterpreter::Initialize() {
527527
528528 cmd_obj_sp = GetCommandSPExact (" scripting run" );
529529 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);
534530 AddAlias (" script" , cmd_obj_sp);
535531 }
536532
@@ -1315,6 +1311,39 @@ CommandObject *CommandInterpreter::GetUserCommandObject(
13151311 return {};
13161312}
13171313
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+
13181347bool CommandInterpreter::CommandExists (llvm::StringRef cmd) const {
13191348 return m_command_dict.find (std::string (cmd)) != m_command_dict.end ();
13201349}
@@ -3434,6 +3463,19 @@ CommandInterpreter::ResolveCommandImpl(std::string &command_line,
34343463 std::string next_word;
34353464 StringList matches;
34363465 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+
34373479 while (!done) {
34383480 char quote_char = ' \0 ' ;
34393481 std::string suffix;
@@ -3445,14 +3487,7 @@ CommandInterpreter::ResolveCommandImpl(std::string &command_line,
34453487 bool is_real_command =
34463488 (!is_alias) || (cmd_obj != nullptr && !cmd_obj->IsAlias ());
34473489 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);
34563491 } else {
34573492 if (cmd_obj) {
34583493 llvm::StringRef cmd_name = cmd_obj->GetCommandName ();
@@ -3499,21 +3534,32 @@ CommandInterpreter::ResolveCommandImpl(std::string &command_line,
34993534 if (cmd_obj == nullptr ) {
35003535 const size_t num_matches = matches.GetSize ();
35013536 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 ());
35053549
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 ());
35083554 }
3509- result.AppendRawError (error_msg.GetString ());
35103555 } else {
35113556 // We didn't have only one match, otherwise we wouldn't get here.
35123557 lldbassert (num_matches == 0 );
35133558 result.AppendErrorWithFormat (" '%s' is not a valid command.\n " ,
35143559 next_word.c_str ());
35153560 }
3516- return nullptr ;
3561+ if (!done)
3562+ return nullptr ;
35173563 }
35183564
35193565 if (cmd_obj->IsMultiwordObject ()) {
0 commit comments