@@ -520,10 +520,6 @@ void CommandInterpreter::Initialize() {
520520
521521 cmd_obj_sp = GetCommandSPExact (" scripting run" );
522522 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);
527523 AddAlias (" script" , cmd_obj_sp);
528524 }
529525
@@ -1302,6 +1298,39 @@ CommandObject *CommandInterpreter::GetUserCommandObject(
13021298 return {};
13031299}
13041300
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+
13051334bool CommandInterpreter::CommandExists (llvm::StringRef cmd) const {
13061335 return m_command_dict.find (std::string (cmd)) != m_command_dict.end ();
13071336}
@@ -3421,6 +3450,19 @@ CommandInterpreter::ResolveCommandImpl(std::string &command_line,
34213450 std::string next_word;
34223451 StringList matches;
34233452 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+
34243466 while (!done) {
34253467 char quote_char = ' \0 ' ;
34263468 std::string suffix;
@@ -3432,14 +3474,7 @@ CommandInterpreter::ResolveCommandImpl(std::string &command_line,
34323474 bool is_real_command =
34333475 (!is_alias) || (cmd_obj != nullptr && !cmd_obj->IsAlias ());
34343476 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);
34433478 } else {
34443479 if (cmd_obj) {
34453480 llvm::StringRef cmd_name = cmd_obj->GetCommandName ();
@@ -3486,21 +3521,32 @@ CommandInterpreter::ResolveCommandImpl(std::string &command_line,
34863521 if (cmd_obj == nullptr ) {
34873522 const size_t num_matches = matches.GetSize ();
34883523 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 ());
34923536
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 ());
34953541 }
3496- result.AppendRawError (error_msg.GetString ());
34973542 } else {
34983543 // We didn't have only one match, otherwise we wouldn't get here.
34993544 lldbassert (num_matches == 0 );
35003545 result.AppendErrorWithFormat (" '%s' is not a valid command.\n " ,
35013546 next_word.c_str ());
35023547 }
3503- return nullptr ;
3548+ if (!done)
3549+ return nullptr ;
35043550 }
35053551
35063552 if (cmd_obj->IsMultiwordObject ()) {
0 commit comments