26 m_can_be_removed(false) {}
54 CommandObject::CommandMap::iterator pos;
57 if (matches ==
nullptr)
58 matches = &local_matches;
62 if (num_matches == 1) {
69 return_cmd_sp = pos->second;
85 "tried to add a CommandObject from a different interpreter");
87 CommandMap::iterator pos;
100 llvm::StringRef name,
const CommandObjectSP &cmd_obj_sp,
bool can_replace) {
104 "tried to add a CommandObject from a different interpreter");
106 return llvm::createStringError(llvm::inconvertibleErrorCode(),
107 "can't add a user subcommand to a builtin container command.");
110 cmd_obj_sp->SetIsUserCommand(
true);
112 std::string str_name(name);
117 return llvm::Error::success();
120 const char *error_str =
nullptr;
122 error_str =
"sub-command already exists";
123 if (!(*pos).second->IsUserCommand())
124 error_str =
"can't replace a builtin subcommand";
127 return llvm::createStringError(llvm::inconvertibleErrorCode(), error_str);
130 return llvm::Error::success();
134 bool must_be_multiword) {
135 CommandMap::iterator pos;
136 std::string str_name(cmd_name);
140 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"subcommand '%s' not found.",
143 if (!(*pos).second->IsUserCommand()) {
144 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"subcommand '%s' not a user command.",
148 if (must_be_multiword && !(*pos).second->IsMultiwordObject()) {
149 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"subcommand '%s' is not a container command",
152 if (!must_be_multiword && (*pos).second->IsMultiwordObject()) {
153 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"subcommand '%s' is not a user command",
159 return llvm::Error::success();
164 Args args(args_string);
171 auto sub_command = args[0].ref();
172 if (sub_command.empty()) {
173 result.
AppendError(
"Need to specify a non-empty subcommand.");
185 if (sub_cmd_obj !=
nullptr) {
191 sub_cmd_obj->
Execute(args_string, result);
195 std::string error_msg;
196 const size_t num_subcmd_matches = matches.
GetSize();
197 if (num_subcmd_matches > 0)
198 error_msg.assign(
"ambiguous command ");
200 error_msg.assign(
"invalid command ");
202 error_msg.append(
"'");
204 error_msg.append(
" ");
205 error_msg.append(std::string(sub_command));
206 error_msg.append(
"'.");
208 if (num_subcmd_matches > 0) {
209 error_msg.append(
" Possible completions:");
210 for (
const std::string &match : matches) {
211 error_msg.append(
"\n\t");
212 error_msg.append(match);
215 error_msg.append(
"\n");
224 output_stream.
PutCString(
"\nThe following subcommands are supported:\n\n");
226 CommandMap::iterator pos;
233 std::string indented_command(
" ");
234 indented_command.append(pos->first);
235 if (pos->second->WantsRawCommandString()) {
236 std::string help_text(std::string(pos->second->GetHelp()));
237 help_text.append(
" Expects 'raw' input (see 'help raw-input'.)");
239 "--", help_text, max_len);
242 "--", pos->second->GetHelp(),
246 output_stream.
PutCString(
"\nFor more help on any particular subcommand, type "
247 "'help <command> <subcommand>'.\n");
258 if (new_matches.
GetSize() == 1 &&
263 if (cmd_obj !=
nullptr) {
278 if (!sub_command_object)
288std::optional<std::string>
296 if (sub_command_object ==
nullptr)
302 const char *name,
const char *help,
303 const char *syntax, uint32_t flags)
318 return proxy_command->
GetHelp();
418std::optional<std::string>
428 return "command is not implemented";
434 proxy_command->Execute(args_string, result);
A command line argument class.
void Shift()
Shifts the first argument C string value of the array off the argument array.
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
void OutputFormattedHelpText(Stream &strm, llvm::StringRef prefix, llvm::StringRef help_text)
void Execute(const char *args_string, CommandReturnObject &result) override
llvm::Error LoadUserSubcommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj, bool can_replace) override
void GenerateHelpText(Stream &output_stream) override
CommandObject::CommandMap m_subcommand_dict
void HandleCompletion(CompletionRequest &request) override
This default version handles calling option argument completions and then calls HandleArgumentComplet...
~CommandObjectMultiword() override
std::optional< std::string > GetRepeatCommand(Args ¤t_command_args, uint32_t index) override
Get the command that appropriate for a "repeat" of the current command.
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
CommandObject * GetSubcommandObject(llvm::StringRef sub_cmd, StringList *matches=nullptr) override
llvm::Error RemoveUserSubcommand(llvm::StringRef cmd_name, bool multiword_okay)
CommandObjectMultiword(CommandInterpreter &interpreter, const char *name, const char *help=nullptr, const char *syntax=nullptr, uint32_t flags=0)
lldb::CommandObjectSP GetSubcommandSPExact(llvm::StringRef sub_cmd) override
lldb::CommandObjectSP GetSubcommandSP(llvm::StringRef sub_cmd, StringList *matches=nullptr) override
void GenerateHelpText(Stream &result) override
bool WantsCompletion() override
virtual CommandObject * GetProxyCommandObject()=0
llvm::StringRef GetHelpLong() override
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The default version handles argument definitions that have only one argument type,...
lldb::CommandObjectSP GetSubcommandSP(llvm::StringRef sub_cmd, StringList *matches=nullptr) override
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
CommandObjectMultiword * GetAsMultiwordCommand() override
llvm::StringRef GetSyntax() override
CommandObject * GetSubcommandObject(llvm::StringRef sub_cmd, StringList *matches=nullptr) override
void Execute(const char *args_string, CommandReturnObject &result) override
CommandObjectProxy(CommandInterpreter &interpreter, const char *name, const char *help=nullptr, const char *syntax=nullptr, uint32_t flags=0)
Options * GetOptions() override
bool IsMultiwordObject() override
virtual llvm::StringRef GetUnsupportedError()
bool WantsRawCommandString() override
void HandleCompletion(CompletionRequest &request) override
This default version handles calling option argument completions and then calls HandleArgumentComplet...
std::optional< std::string > GetRepeatCommand(Args ¤t_command_args, uint32_t index) override
Get the command that appropriate for a "repeat" of the current command.
bool IsRemovable() const override
~CommandObjectProxy() override
llvm::StringRef GetHelp() override
virtual bool WantsRawCommandString()=0
void GenerateHelpText(CommandReturnObject &result)
virtual llvm::StringRef GetHelpLong()
llvm::StringRef GetCommandName() const
virtual bool IsMultiwordObject()
virtual bool WantsCompletion()
CommandInterpreter & GetCommandInterpreter()
virtual void Execute(const char *args_string, CommandReturnObject &result)=0
CommandInterpreter & m_interpreter
virtual bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj)
virtual std::optional< std::string > GetRepeatCommand(Args ¤t_command_args, uint32_t index)
Get the command that appropriate for a "repeat" of the current command.
virtual CommandObject * GetSubcommandObject(llvm::StringRef sub_cmd, StringList *matches=nullptr)
virtual CommandObjectMultiword * GetAsMultiwordCommand()
virtual Options * GetOptions()
virtual void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector)
The default version handles argument definitions that have only one argument type,...
virtual llvm::StringRef GetSyntax()
virtual bool IsRemovable() const
virtual void HandleCompletion(CompletionRequest &request)
This default version handles calling option argument completions and then calls HandleArgumentComplet...
virtual llvm::StringRef GetHelp()
virtual lldb::CommandObjectSP GetSubcommandSP(llvm::StringRef sub_cmd, StringList *matches=nullptr)
void void AppendError(llvm::StringRef in_string)
void AppendRawError(llvm::StringRef in_string)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
"lldb/Utility/ArgCompletionRequest.h"
void AddCompletions(const StringList &completions)
Adds multiple possible completion strings.
const Args & GetParsedLine() const
void ShiftArguments()
Drops the first argument from the argument list.
void AppendEmptyArgument()
Adds an empty argument at the end of the argument list and moves the cursor to this new argument.
size_t GetCursorIndex() const
A command line option parsing protocol class.
A stream class that can stream formatted output to a file.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
void AppendString(const std::string &s)
const char * GetStringAtIndex(size_t idx) const
void DeleteStringAtIndex(size_t id)
A class that represents a running process on the host machine.
int AddNamesMatchingPartialString(const std::map< std::string, ValueType > &in_map, llvm::StringRef cmd_str, StringList &matches, StringList *descriptions=nullptr)
std::vector< OptionArgElement > OptionElementVector
size_t FindLongestCommandWord(std::map< std::string, ValueType > &dict)
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP