1 //===-- CommandAlias.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 LLDB_INTERPRETER_COMMANDALIAS_H
10 #define LLDB_INTERPRETER_COMMANDALIAS_H
11 
12 #include <memory>
13 
14 #include "lldb/Interpreter/CommandObject.h"
15 #include "lldb/Utility/Args.h"
16 #include "lldb/Utility/CompletionRequest.h"
17 #include "lldb/lldb-forward.h"
18 
19 namespace lldb_private {
20 class CommandAlias : public CommandObject {
21 public:
22   typedef std::unique_ptr<CommandAlias> UniquePointer;
23 
24   CommandAlias(CommandInterpreter &interpreter, lldb::CommandObjectSP cmd_sp,
25                llvm::StringRef options_args, llvm::StringRef name,
26                llvm::StringRef help = llvm::StringRef(),
27                llvm::StringRef syntax = llvm::StringRef(), uint32_t flags = 0);
28 
29   void GetAliasExpansion(StreamString &help_string) const;
30 
IsValid()31   bool IsValid() const { return m_underlying_command_sp && m_option_args_sp; }
32 
33   explicit operator bool() const { return IsValid(); }
34 
35   bool WantsRawCommandString() override;
36 
37   bool WantsCompletion() override;
38 
39   void HandleCompletion(CompletionRequest &request) override;
40 
41   void
42   HandleArgumentCompletion(CompletionRequest &request,
43                            OptionElementVector &opt_element_vector) override;
44 
45   Options *GetOptions() override;
46 
IsAlias()47   bool IsAlias() override { return true; }
48 
49   bool IsDashDashCommand() override;
50 
51   llvm::StringRef GetHelp() override;
52 
53   llvm::StringRef GetHelpLong() override;
54 
55   void SetHelp(llvm::StringRef str) override;
56 
57   void SetHelpLong(llvm::StringRef str) override;
58 
59   bool Execute(const char *args_string, CommandReturnObject &result) override;
60 
GetUnderlyingCommand()61   lldb::CommandObjectSP GetUnderlyingCommand() {
62     return m_underlying_command_sp;
63   }
GetOptionArguments()64   OptionArgVectorSP GetOptionArguments() const { return m_option_args_sp; }
GetOptionString()65   const char *GetOptionString() { return m_option_string.c_str(); }
66 
67   // this takes an alias - potentially nested (i.e. an alias to an alias) and
68   // expands it all the way to a non-alias command
69   std::pair<lldb::CommandObjectSP, OptionArgVectorSP> Desugar();
70 
71 protected:
72   bool IsNestedAlias();
73 
74 private:
75   lldb::CommandObjectSP m_underlying_command_sp;
76   std::string m_option_string;
77   OptionArgVectorSP m_option_args_sp;
78   LazyBool m_is_dashdash_alias;
79   bool m_did_set_help : 1;
80   bool m_did_set_help_long : 1;
81 };
82 } // namespace lldb_private
83 
84 #endif // LLDB_INTERPRETER_COMMANDALIAS_H
85