Skip to content

Commit 8dfb266

Browse files
committed
addressed review comments: reword error msg and rename helper func
1 parent 4493bf0 commit 8dfb266

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

lldb/include/lldb/Interpreter/CommandObjectMultiword.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class CommandObjectMultiword : public CommandObject {
7070
return m_subcommand_dict;
7171
}
7272

73-
std::string GetTopSubcommands(int count);
73+
std::string GetSubcommandsHintText();
7474

7575
CommandObject::CommandMap m_subcommand_dict;
7676
bool m_can_be_removed;

lldb/source/Commands/CommandObjectMultiword.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -208,33 +208,37 @@ void CommandObjectMultiword::Execute(const char *args_string,
208208
error_msg.append(match);
209209
}
210210
} else {
211-
// Rather than simply complaining about the invalid (sub) command,
212-
// try to offer some alternatives.
213-
// This is especially useful for cases where the user types something
214-
// seamingly trivial, such as `breakpoint foo`.
211+
// Try to offer some alternatives to help correct the command.
215212
error_msg.assign(
216213
llvm::Twine("'" + sub_command + "' is not a valid subcommand of \"" +
217-
GetCommandName() + "\". Valid subcommands are " +
218-
GetTopSubcommands(/*count=*/5) + ". Use \"help " +
219-
GetCommandName() + "\" to find out more.")
214+
GetCommandName() + "\"." + GetSubcommandsHintText() +
215+
" Use \"help " + GetCommandName() + "\" to find out more.")
220216
.str());
221217
}
222218
error_msg.append("\n");
223219
result.AppendRawError(error_msg.c_str());
224220
}
225221

226-
std::string CommandObjectMultiword::GetTopSubcommands(int count) {
222+
std::string CommandObjectMultiword::GetSubcommandsHintText() {
227223
if (m_subcommand_dict.empty())
228-
return "<NONE>";
229-
std::string buffer = "{";
224+
return "";
225+
const size_t maxCount = 5;
226+
size_t i = 0;
227+
std::string buffer = " Valid subcommand";
228+
buffer.append(m_subcommand_dict.size() > 1 ? "s are:" : "is");
230229
CommandMap::iterator pos;
231230
for (pos = m_subcommand_dict.begin();
232-
pos != m_subcommand_dict.end() && count > 0; ++pos, --count) {
233-
buffer.append("'");
231+
pos != m_subcommand_dict.end() && i < maxCount; ++pos, ++i) {
232+
buffer.append(" ");
234233
buffer.append(pos->first);
235-
buffer.append("',");
234+
buffer.append(",");
236235
}
237-
buffer.append("...}");
236+
if (i < m_subcommand_dict.size())
237+
buffer.append(" and others");
238+
else
239+
buffer.pop_back();
240+
241+
buffer.append(".");
238242
return buffer;
239243
}
240244

0 commit comments

Comments
 (0)