xref: /llvm-project/lldb/source/Commands/CommandObjectHelp.h (revision b9c1b51e45b845debb76d8658edabca70ca56079)
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 public:
28   CommandObjectHelp(CommandInterpreter &interpreter);
29 
30   ~CommandObjectHelp() override;
31 
32   int HandleCompletion(Args &input, int &cursor_index,
33                        int &cursor_char_position, int match_start_point,
34                        int max_return_elements, bool &word_complete,
35                        StringList &matches) override;
36 
37   static void GenerateAdditionalHelpAvenuesMessage(
38       Stream *s, const char *command, const char *prefix = nullptr,
39       const char *subcommand = nullptr, bool include_apropos = true,
40       bool include_type_lookup = true);
41 
42   class CommandOptions : public Options {
43   public:
44     CommandOptions() : Options() {}
45 
46     ~CommandOptions() override {}
47 
48     Error SetOptionValue(uint32_t option_idx, const char *option_arg,
49                          ExecutionContext *execution_context) override {
50       Error error;
51       const int short_option = m_getopt_table[option_idx].val;
52 
53       switch (short_option) {
54       case 'a':
55         m_show_aliases = false;
56         break;
57       case 'u':
58         m_show_user_defined = false;
59         break;
60       case 'h':
61         m_show_hidden = true;
62         break;
63       default:
64         error.SetErrorStringWithFormat("unrecognized option '%c'",
65                                        short_option);
66         break;
67       }
68 
69       return error;
70     }
71 
72     void OptionParsingStarting(ExecutionContext *execution_context) override {
73       m_show_aliases = true;
74       m_show_user_defined = true;
75       m_show_hidden = false;
76     }
77 
78     const OptionDefinition *GetDefinitions() override { return g_option_table; }
79 
80     // Options table: Required for subclasses of Options.
81 
82     static OptionDefinition g_option_table[];
83 
84     // Instance variables to hold the values for command options.
85 
86     bool m_show_aliases;
87     bool m_show_user_defined;
88     bool m_show_hidden;
89   };
90 
91   Options *GetOptions() override { return &m_options; }
92 
93 protected:
94   bool DoExecute(Args &command, CommandReturnObject &result) override;
95 
96 private:
97   CommandOptions m_options;
98 };
99 
100 } // namespace lldb_private
101 
102 #endif // liblldb_CommandObjectHelp_h_
103