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 "lldb/lldb-python.h"
12 #include "CommandObjectSyntax.h"
16 // Other libraries and framework includes
18 #include "lldb/Interpreter/Args.h"
19 #include "lldb/Interpreter/Options.h"
21 #include "lldb/Interpreter/CommandInterpreter.h"
22 #include "lldb/Interpreter/CommandReturnObject.h"
23 #include "lldb/Interpreter/CommandObjectMultiword.h"
26 using namespace lldb_private;
28 //-------------------------------------------------------------------------
29 // CommandObjectSyntax
30 //-------------------------------------------------------------------------
32 CommandObjectSyntax::CommandObjectSyntax (CommandInterpreter &interpreter) :
33 CommandObjectParsed (interpreter,
35 "Shows the correct syntax for a given debugger command.",
38 CommandArgumentEntry arg;
39 CommandArgumentData command_arg;
41 // Define the first (and only) variant of this arg.
42 command_arg.arg_type = eArgTypeCommandName;
43 command_arg.arg_repetition = eArgRepeatPlain;
45 // There is only one variant this argument could be; put it into the argument entry.
46 arg.push_back (command_arg);
48 // Push the data for the first argument into the m_arguments vector.
49 m_arguments.push_back (arg);
52 CommandObjectSyntax::~CommandObjectSyntax()
58 CommandObjectSyntax::DoExecute (Args& command, CommandReturnObject &result)
60 CommandObject::CommandMap::iterator pos;
61 CommandObject *cmd_obj;
62 const size_t argc = command.GetArgumentCount();
66 cmd_obj = m_interpreter.GetCommandObject (command.GetArgumentAtIndex(0));
68 for (size_t i = 1; i < argc; ++i)
70 std::string sub_command = command.GetArgumentAtIndex (i);
71 if (!cmd_obj->IsMultiwordObject())
78 cmd_obj = cmd_obj->GetSubcommandObject(sub_command.c_str());
87 if (all_okay && (cmd_obj != NULL))
89 Stream &output_strm = result.GetOutputStream();
90 if (cmd_obj->GetOptions() != NULL)
92 output_strm.Printf ("\nSyntax: %s\n", cmd_obj->GetSyntax());
93 output_strm.Printf ("(Try 'help %s' for more information on command options syntax.)\n",
94 cmd_obj->GetCommandName());
95 result.SetStatus (eReturnStatusSuccessFinishNoResult);
99 output_strm.Printf ("\nSyntax: %s\n", cmd_obj->GetSyntax());
100 result.SetStatus (eReturnStatusSuccessFinishNoResult);
105 std::string cmd_string;
106 command.GetCommandString (cmd_string);
107 result.AppendErrorWithFormat ("'%s' is not a known command.\n", cmd_string.c_str());
108 result.AppendError ("Try 'help' to see a current list of commands.");
109 result.SetStatus (eReturnStatusFailed);
114 result.AppendError ("Must call 'syntax' with a valid command.");
115 result.SetStatus (eReturnStatusFailed);
118 return result.Succeeded();