================ @@ -194,28 +194,54 @@ void CommandObjectMultiword::Execute(const char *args_string, std::string error_msg; const size_t num_subcmd_matches = matches.GetSize(); - if (num_subcmd_matches > 0) + if (num_subcmd_matches > 0) { error_msg.assign("ambiguous command "); - else - error_msg.assign("invalid command "); - - error_msg.append("'"); - error_msg.append(std::string(GetCommandName())); - error_msg.append(" "); - error_msg.append(std::string(sub_command)); - error_msg.append("'."); + error_msg.append("'"); + error_msg.append(std::string(GetCommandName())); + error_msg.append(" "); + error_msg.append(std::string(sub_command)); + error_msg.append("'."); - if (num_subcmd_matches > 0) { error_msg.append(" Possible completions:"); for (const std::string &match : matches) { error_msg.append("\n\t"); error_msg.append(match); } + } else { + // Try to offer some alternatives to help correct the command. + error_msg.assign( + llvm::Twine("'" + sub_command + "' is not a valid subcommand of \"" + + GetCommandName() + "\"." + GetSubcommandsHintText() + + " Use \"help " + GetCommandName() + "\" to find out more.") + .str()); } error_msg.append("\n"); result.AppendRawError(error_msg.c_str()); } +std::string CommandObjectMultiword::GetSubcommandsHintText() { + if (m_subcommand_dict.empty()) + return ""; + const size_t maxCount = 5; + size_t i = 0; + std::string buffer = " Valid subcommand"; + buffer.append(m_subcommand_dict.size() > 1 ? "s are:" : "is"); ---------------- oontvoo wrote:
> You're missing a space before "is" Done. > The output will also be garbled for the case of zero subcommands Which output? the error msg as a whole or just this function's output? unless i'm missing something, if there are zero subcommands, the function would have returned "" on line 223, which means the error message would have been something like `"foo" is not a valid subcommand of "breakpoint". Use "help breakpoint" to find out more.` (ie., there will be no suggestions on subcommands). https://github.com/llvm/llvm-project/pull/111891 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits