xref: /llvm-project/lldb/source/Commands/CommandObjectHelp.h (revision e1cfbc79420fee0b71bad62f8d413b68a0eca91e)
1 //===-- CommandObjectHelp.h -------------------------------------*- 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 #ifndef liblldb_CommandObjectHelp_h_
11 #define liblldb_CommandObjectHelp_h_
12 
13 // C Includes
14 // C++ Includes
15 // Other libraries and framework includes
16 // Project includes
17 #include "lldb/Interpreter/CommandObject.h"
18 #include "lldb/Interpreter/Options.h"
19 
20 namespace lldb_private {
21 
22 //-------------------------------------------------------------------------
23 // CommandObjectHelp
24 //-------------------------------------------------------------------------
25 
26 class CommandObjectHelp : public CommandObjectParsed
27 {
28 public:
29 
30     CommandObjectHelp (CommandInterpreter &interpreter);
31 
32     ~CommandObjectHelp() override;
33 
34     int
35     HandleCompletion(Args &input,
36 		     int &cursor_index,
37 		     int &cursor_char_position,
38 		     int match_start_point,
39 		     int max_return_elements,
40 		     bool &word_complete,
41 		     StringList &matches) override;
42 
43     static void
44     GenerateAdditionalHelpAvenuesMessage (Stream *s,
45                                           const char* command,
46                                           const char* prefix = nullptr,
47                                           const char* subcommand = nullptr,
48                                           bool include_apropos = true,
49                                           bool include_type_lookup = true);
50 
51     class CommandOptions : public Options
52     {
53     public:
54 
55         CommandOptions() :
56         Options()
57         {
58         }
59 
60         ~CommandOptions() override {}
61 
62         Error
63         SetOptionValue(uint32_t option_idx, const char *option_arg,
64                        ExecutionContext *execution_context) override
65         {
66             Error error;
67             const int short_option = m_getopt_table[option_idx].val;
68 
69             switch (short_option)
70             {
71                 case 'a':
72                     m_show_aliases = false;
73                     break;
74                 case 'u':
75                     m_show_user_defined = false;
76                     break;
77                 case 'h':
78                     m_show_hidden = true;
79                     break;
80                 default:
81                     error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
82                     break;
83             }
84 
85             return error;
86         }
87 
88         void
89         OptionParsingStarting(ExecutionContext *execution_context) override
90         {
91             m_show_aliases = true;
92             m_show_user_defined = true;
93             m_show_hidden = false;
94         }
95 
96         const OptionDefinition*
97         GetDefinitions() override
98         {
99             return g_option_table;
100         }
101 
102         // Options table: Required for subclasses of Options.
103 
104         static OptionDefinition g_option_table[];
105 
106         // Instance variables to hold the values for command options.
107 
108         bool m_show_aliases;
109         bool m_show_user_defined;
110         bool m_show_hidden;
111     };
112 
113     Options *
114     GetOptions() override
115     {
116         return &m_options;
117     }
118 
119 protected:
120     bool
121     DoExecute(Args& command,
122 	      CommandReturnObject &result) override;
123 
124 private:
125     CommandOptions m_options;
126 };
127 
128 } // namespace lldb_private
129 
130 #endif // liblldb_CommandObjectHelp_h_
131