1 //===-- CommandObjectSyntax.cpp ---------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "CommandObjectSyntax.h"
14 // Other libraries and framework includes
16 #include "lldb/Interpreter/Args.h"
17 #include "lldb/Interpreter/Options.h"
19 #include "lldb/Interpreter/CommandInterpreter.h"
20 #include "lldb/Interpreter/CommandReturnObject.h"
21 #include "lldb/Interpreter/CommandObjectMultiword.h"
24 using namespace lldb_private;
26 //-------------------------------------------------------------------------
27 // CommandObjectSyntax
28 //-------------------------------------------------------------------------
30 CommandObjectSyntax::CommandObjectSyntax (CommandInterpreter &interpreter) :
31 CommandObjectParsed (interpreter,
33 "Shows the correct syntax for a given debugger command.",
36 CommandArgumentEntry arg;
37 CommandArgumentData command_arg;
39 // Define the first (and only) variant of this arg.
40 command_arg.arg_type = eArgTypeCommandName;
41 command_arg.arg_repetition = eArgRepeatPlain;
43 // There is only one variant this argument could be; put it into the argument entry.
44 arg.push_back (command_arg);
46 // Push the data for the first argument into the m_arguments vector.
47 m_arguments.push_back (arg);
50 CommandObjectSyntax::~CommandObjectSyntax()
56 CommandObjectSyntax::DoExecute (Args& command, CommandReturnObject &result)
58 CommandObject::CommandMap::iterator pos;
59 CommandObject *cmd_obj;
60 const size_t argc = command.GetArgumentCount();
64 cmd_obj = m_interpreter.GetCommandObject (command.GetArgumentAtIndex(0));
66 for (size_t i = 1; i < argc; ++i)
68 std::string sub_command = command.GetArgumentAtIndex (i);
69 if (!cmd_obj->IsMultiwordObject())
76 cmd_obj = cmd_obj->GetSubcommandObject(sub_command.c_str());
85 if (all_okay && (cmd_obj != NULL))
87 Stream &output_strm = result.GetOutputStream();
88 if (cmd_obj->GetOptions() != NULL)
90 output_strm.Printf ("\nSyntax: %s\n", cmd_obj->GetSyntax());
91 output_strm.Printf ("(Try 'help %s' for more information on command options syntax.)\n",
92 cmd_obj->GetCommandName());
93 result.SetStatus (eReturnStatusSuccessFinishNoResult);
97 output_strm.Printf ("\nSyntax: %s\n", cmd_obj->GetSyntax());
98 result.SetStatus (eReturnStatusSuccessFinishNoResult);
103 std::string cmd_string;
104 command.GetCommandString (cmd_string);
105 result.AppendErrorWithFormat ("'%s' is not a known command.\n", cmd_string.c_str());
106 result.AppendError ("Try 'help' to see a current list of commands.");
107 result.SetStatus (eReturnStatusFailed);
112 result.AppendError ("Must call 'syntax' with a valid command.");
113 result.SetStatus (eReturnStatusFailed);
116 return result.Succeeded();