1 //===-- CommandObjectApropos.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 "CommandObjectApropos.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"
25 using namespace lldb_private;
27 //-------------------------------------------------------------------------
28 // CommandObjectApropos
29 //-------------------------------------------------------------------------
31 CommandObjectApropos::CommandObjectApropos (CommandInterpreter &interpreter) :
32 CommandObjectParsed (interpreter,
34 "Find a list of debugger commands related to a particular word/subject.",
37 CommandArgumentEntry arg;
38 CommandArgumentData search_word_arg;
40 // Define the first (and only) variant of this arg.
41 search_word_arg.arg_type = eArgTypeSearchWord;
42 search_word_arg.arg_repetition = eArgRepeatPlain;
44 // There is only one variant this argument could be; put it into the argument entry.
45 arg.push_back (search_word_arg);
47 // Push the data for the first argument into the m_arguments vector.
48 m_arguments.push_back (arg);
51 CommandObjectApropos::~CommandObjectApropos()
57 CommandObjectApropos::DoExecute (Args& args, CommandReturnObject &result)
59 const size_t argc = args.GetArgumentCount ();
63 const char *search_word = args.GetArgumentAtIndex(0);
64 if ((search_word != NULL)
65 && (strlen (search_word) > 0))
67 // The bulk of the work must be done inside the Command Interpreter, since the command dictionary
69 StringList commands_found;
70 StringList commands_help;
71 StringList user_commands_found;
72 StringList user_commands_help;
74 m_interpreter.FindCommandsForApropos (search_word, commands_found, commands_help, true, false);
75 m_interpreter.FindCommandsForApropos (search_word, user_commands_found, user_commands_help, false, true);
77 if (commands_found.GetSize() == 0 && user_commands_found.GetSize() == 0)
79 result.AppendMessageWithFormat ("No commands found pertaining to '%s'. Try 'help' to see a complete list of debugger commands.\n", search_word);
83 if (commands_found.GetSize() > 0)
85 result.AppendMessageWithFormat ("The following built-in commands may relate to '%s':\n", search_word);
88 for (size_t i = 0; i < commands_found.GetSize(); ++i)
90 size_t len = strlen (commands_found.GetStringAtIndex (i));
95 for (size_t i = 0; i < commands_found.GetSize(); ++i)
96 m_interpreter.OutputFormattedHelpText (result.GetOutputStream(),
97 commands_found.GetStringAtIndex(i),
99 commands_help.GetStringAtIndex(i),
101 if (user_commands_found.GetSize() > 0)
102 result.AppendMessage("");
105 if (user_commands_found.GetSize() > 0)
107 result.AppendMessageWithFormat ("The following user commands may relate to '%s':\n", search_word);
110 for (size_t i = 0; i < user_commands_found.GetSize(); ++i)
112 size_t len = strlen (user_commands_found.GetStringAtIndex (i));
117 for (size_t i = 0; i < user_commands_found.GetSize(); ++i)
118 m_interpreter.OutputFormattedHelpText (result.GetOutputStream(),
119 user_commands_found.GetStringAtIndex(i),
121 user_commands_help.GetStringAtIndex(i),
128 std::vector<const Property *> properties;
129 const size_t num_properties = m_interpreter.GetDebugger().Apropos(search_word, properties);
132 const bool dump_qualified_name = true;
133 result.AppendMessageWithFormat ("\nThe following settings variables may relate to '%s': \n\n", search_word);
134 for (size_t i=0; i<num_properties; ++i)
135 properties[i]->DumpDescription (m_interpreter, result.GetOutputStream(), 0, dump_qualified_name);
139 result.SetStatus (eReturnStatusSuccessFinishNoResult);
143 result.AppendError ("'' is not a valid search word.\n");
144 result.SetStatus (eReturnStatusFailed);
149 result.AppendError ("'apropos' must be called with exactly one argument.\n");
150 result.SetStatus (eReturnStatusFailed);
153 return result.Succeeded();