xref: /llvm-project/lldb/source/Commands/CommandObjectHelp.h (revision d5b440369dbb0d41e6ecd47d6ac7410201e27f17)
1 //===-- CommandObjectHelp.h -------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef liblldb_CommandObjectHelp_h_
10 #define liblldb_CommandObjectHelp_h_
11 
12 #include "lldb/Host/OptionParser.h"
13 #include "lldb/Interpreter/CommandObject.h"
14 #include "lldb/Interpreter/Options.h"
15 
16 namespace lldb_private {
17 
18 //-------------------------------------------------------------------------
19 // CommandObjectHelp
20 //-------------------------------------------------------------------------
21 
22 class CommandObjectHelp : public CommandObjectParsed {
23 public:
24   CommandObjectHelp(CommandInterpreter &interpreter);
25 
26   ~CommandObjectHelp() override;
27 
28   int HandleCompletion(CompletionRequest &request) override;
29 
30   static void GenerateAdditionalHelpAvenuesMessage(
31       Stream *s, llvm::StringRef command, llvm::StringRef prefix,
32       llvm::StringRef subcommand, bool include_upropos = true,
33       bool include_type_lookup = true);
34 
35   class CommandOptions : public Options {
36   public:
37     CommandOptions() : Options() {}
38 
39     ~CommandOptions() override {}
40 
41     Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
42                           ExecutionContext *execution_context) override {
43       Status error;
44       const int short_option = m_getopt_table[option_idx].val;
45 
46       switch (short_option) {
47       case 'a':
48         m_show_aliases = false;
49         break;
50       case 'u':
51         m_show_user_defined = false;
52         break;
53       case 'h':
54         m_show_hidden = true;
55         break;
56       default:
57         error.SetErrorStringWithFormat("unrecognized option '%c'",
58                                        short_option);
59         break;
60       }
61 
62       return error;
63     }
64 
65     void OptionParsingStarting(ExecutionContext *execution_context) override {
66       m_show_aliases = true;
67       m_show_user_defined = true;
68       m_show_hidden = false;
69     }
70 
71     llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
72 
73     // Instance variables to hold the values for command options.
74 
75     bool m_show_aliases;
76     bool m_show_user_defined;
77     bool m_show_hidden;
78   };
79 
80   Options *GetOptions() override { return &m_options; }
81 
82 protected:
83   bool DoExecute(Args &command, CommandReturnObject &result) override;
84 
85 private:
86   CommandOptions m_options;
87 };
88 
89 } // namespace lldb_private
90 
91 #endif // liblldb_CommandObjectHelp_h_
92