blob: 0f10b3ec780d3790ef1c6a92a4de2ed016f1fece [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- CommandObjectApropos.cpp ---------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "CommandObjectApropos.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
Jim Ingham84cdc152010-06-15 19:49:27 +000016#include "lldb/Interpreter/Args.h"
17#include "lldb/Interpreter/Options.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018
19#include "lldb/Interpreter/CommandInterpreter.h"
20#include "lldb/Interpreter/CommandReturnObject.h"
21#include "lldb/Interpreter/CommandObjectMultiword.h"
22
23using namespace lldb;
24using namespace lldb_private;
25
26//-------------------------------------------------------------------------
27// CommandObjectApropos
28//-------------------------------------------------------------------------
29
30CommandObjectApropos::CommandObjectApropos () :
31 CommandObject ("apropos",
32 "Finds a list of debugger commands related to a particular word/subject.",
33 "apropos <search-word>")
34{
35}
36
37CommandObjectApropos::~CommandObjectApropos()
38{
39}
40
41
42bool
Greg Clayton63094e02010-06-23 01:19:29 +000043CommandObjectApropos::Execute
44(
45 CommandInterpreter &interpreter,
46 Args& args,
47 CommandReturnObject &result
48)
Chris Lattner24943d22010-06-08 16:52:24 +000049{
Greg Clayton63094e02010-06-23 01:19:29 +000050 const int argc = args.GetArgumentCount ();
Chris Lattner24943d22010-06-08 16:52:24 +000051
52 if (argc == 1)
53 {
Greg Clayton63094e02010-06-23 01:19:29 +000054 const char *search_word = args.GetArgumentAtIndex(0);
Chris Lattner24943d22010-06-08 16:52:24 +000055 if ((search_word != NULL)
56 && (strlen (search_word) > 0))
57 {
58 // The bulk of the work must be done inside the Command Interpreter, since the command dictionary
59 // is private.
60 StringList commands_found;
61 StringList commands_help;
Greg Clayton63094e02010-06-23 01:19:29 +000062 interpreter.FindCommandsForApropos (search_word, commands_found, commands_help);
Chris Lattner24943d22010-06-08 16:52:24 +000063 if (commands_found.GetSize() == 0)
64 {
65 result.AppendMessageWithFormat ("No commands found pertaining to '%s'.", search_word);
66 result.AppendMessage ("Try 'help' to see a complete list of debugger commands.");
67 }
68 else
69 {
70 result.AppendMessageWithFormat ("The following commands may relate to '%s':\n", search_word);
71 size_t max_len = 0;
72
73 for (int i = 0; i < commands_found.GetSize(); ++i)
74 {
75 int len = strlen (commands_found.GetStringAtIndex (i));
76 if (len > max_len)
77 max_len = len;
78 }
79
80 for (int i = 0; i < commands_found.GetSize(); ++i)
Greg Clayton63094e02010-06-23 01:19:29 +000081 interpreter.OutputFormattedHelpText (result.GetOutputStream(),
82 commands_found.GetStringAtIndex(i),
83 "--", commands_help.
84 GetStringAtIndex(i),
85 max_len);
Chris Lattner24943d22010-06-08 16:52:24 +000086
87 }
88 result.SetStatus (eReturnStatusSuccessFinishNoResult);
89 }
90 else
91 {
92 result.AppendError ("'' is not a valid search word.\n");
93 result.SetStatus (eReturnStatusFailed);
94 }
95 }
96 else
97 {
98 result.AppendError ("'apropos' must be called with exactly one argument.\n");
99 result.SetStatus (eReturnStatusFailed);
100 }
101
102 return result.Succeeded();
103}