summaryrefslogtreecommitdiffstats
path: root/lldb/source/Commands/CommandObjectSyntax.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Commands/CommandObjectSyntax.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectSyntax.cpp86
1 files changed, 41 insertions, 45 deletions
diff --git a/lldb/source/Commands/CommandObjectSyntax.cpp b/lldb/source/Commands/CommandObjectSyntax.cpp
index ac3f8767cde..2b83b1b8786 100644
--- a/lldb/source/Commands/CommandObjectSyntax.cpp
+++ b/lldb/source/Commands/CommandObjectSyntax.cpp
@@ -54,53 +54,49 @@ bool CommandObjectSyntax::DoExecute(Args &command,
CommandObject *cmd_obj;
const size_t argc = command.GetArgumentCount();
- if (argc > 0) {
- cmd_obj = m_interpreter.GetCommandObject(command.GetArgumentAtIndex(0));
- bool all_okay = true;
- // TODO: Convert to entry-based iteration. Requires converting
- // GetSubcommandObject.
- for (size_t i = 1; i < argc; ++i) {
- std::string sub_command = command.GetArgumentAtIndex(i);
- if (!cmd_obj->IsMultiwordObject()) {
- all_okay = false;
- break;
- } else {
- cmd_obj = cmd_obj->GetSubcommandObject(sub_command.c_str());
- if (!cmd_obj) {
- all_okay = false;
- break;
- }
- }
- }
-
- if (all_okay && (cmd_obj != nullptr)) {
- Stream &output_strm = result.GetOutputStream();
- if (cmd_obj->GetOptions() != nullptr) {
- output_strm.Printf("\nSyntax: %s\n", cmd_obj->GetSyntax().str().c_str());
- output_strm.Printf(
- "(Try 'help %s' for more information on command options syntax.)\n",
- cmd_obj->GetCommandName().str().c_str());
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- } else {
- output_strm.Printf("\nSyntax: %s\n", cmd_obj->GetSyntax().str().c_str());
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- }
- } else {
- std::string cmd_string;
- command.GetCommandString(cmd_string);
-
- StreamString error_msg_stream;
- const bool generate_apropos = true;
- const bool generate_type_lookup = false;
- CommandObjectHelp::GenerateAdditionalHelpAvenuesMessage(
- &error_msg_stream, cmd_string, "", "",
- generate_apropos, generate_type_lookup);
- result.AppendErrorWithFormat("%s", error_msg_stream.GetData());
- result.SetStatus(eReturnStatusFailed);
- }
- } else {
+ if (argc == 0) {
result.AppendError("Must call 'syntax' with a valid command.");
result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ cmd_obj = m_interpreter.GetCommandObject(command[0].ref);
+ bool all_okay = llvm::all_of(
+ command.entries().drop_front(), [&cmd_obj](const Args::ArgEntry &e) {
+ if (!cmd_obj || !cmd_obj->IsMultiwordObject())
+ return false;
+
+ if (!(cmd_obj = cmd_obj->GetSubcommandObject(e.ref)))
+ return false;
+
+ return true;
+ });
+
+ if (!all_okay) {
+ std::string cmd_string;
+ command.GetCommandString(cmd_string);
+
+ StreamString error_msg_stream;
+ const bool generate_apropos = true;
+ const bool generate_type_lookup = false;
+ CommandObjectHelp::GenerateAdditionalHelpAvenuesMessage(
+ &error_msg_stream, cmd_string, "", "", generate_apropos,
+ generate_type_lookup);
+ result.AppendErrorWithFormat("%s", error_msg_stream.GetData());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ Stream &output_strm = result.GetOutputStream();
+ if (cmd_obj->GetOptions() != nullptr) {
+ output_strm.Printf("\nSyntax: %s\n", cmd_obj->GetSyntax().str().c_str());
+ output_strm.Printf(
+ "(Try 'help %s' for more information on command options syntax.)\n",
+ cmd_obj->GetCommandName().str().c_str());
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ } else {
+ output_strm.Printf("\nSyntax: %s\n", cmd_obj->GetSyntax().str().c_str());
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
}
return result.Succeeded();
OpenPOWER on IntegriCloud