aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/getopt/small/completion_generator.h
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/getopt/small/completion_generator.h
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/getopt/small/completion_generator.h')
-rw-r--r--library/cpp/getopt/small/completion_generator.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/library/cpp/getopt/small/completion_generator.h b/library/cpp/getopt/small/completion_generator.h
new file mode 100644
index 0000000000..4241bb7d6c
--- /dev/null
+++ b/library/cpp/getopt/small/completion_generator.h
@@ -0,0 +1,69 @@
+#pragma once
+
+#include "completer.h"
+#include "formatted_output.h"
+#include "last_getopt_opts.h"
+#include "modchooser.h"
+
+#include <util/generic/variant.h>
+#include <util/string/builder.h>
+
+namespace NLastGetopt {
+ class TCompletionGenerator {
+ public:
+ explicit TCompletionGenerator(const TModChooser* modChooser);
+ explicit TCompletionGenerator(const TOpts* opts);
+ virtual ~TCompletionGenerator() = default;
+
+ public:
+ virtual void Generate(TStringBuf command, IOutputStream& stream) = 0;
+
+ protected:
+ std::variant<const TModChooser*, const TOpts*> Options_;
+ };
+
+ class TZshCompletionGenerator: public TCompletionGenerator {
+ public:
+ using TCompletionGenerator::TCompletionGenerator;
+
+ public:
+ void Generate(TStringBuf command, IOutputStream& stream) override;
+
+ private:
+ static void GenerateModesCompletion(TFormattedOutput& out, const TModChooser& chooser, NComp::TCompleterManager& manager);
+ static void GenerateOptsCompletion(TFormattedOutput& out, const TOpts& opts, NComp::TCompleterManager& manager);
+ static void GenerateDefaultOptsCompletion(TFormattedOutput& out, NComp::TCompleterManager& manager);
+ static void GenerateOptCompletion(TFormattedOutput& out, const TOpts& opts, const TOpt& opt, NComp::TCompleterManager& manager);
+ };
+
+ class TBashCompletionGenerator: public TCompletionGenerator {
+ public:
+ using TCompletionGenerator::TCompletionGenerator;
+
+ public:
+ void Generate(TStringBuf command, IOutputStream& stream) override;
+
+ private:
+ static void GenerateModesCompletion(TFormattedOutput& out, const TModChooser& chooser, NComp::TCompleterManager& manager, size_t level);
+ static void GenerateOptsCompletion(TFormattedOutput& out, const TOpts& opts, NComp::TCompleterManager& manager, size_t level);
+ static void GenerateDefaultOptsCompletion(TFormattedOutput& out, NComp::TCompleterManager& manager);
+ };
+
+ namespace NEscaping {
+ /// Escape ':', '-', '=', '[', ']' for use in zsh _arguments
+ TString Q(TStringBuf string);
+ TString QQ(TStringBuf string);
+
+ /// Escape colons for use in zsh _alternative and _arguments
+ TString C(TStringBuf string);
+ TString CC(TStringBuf string);
+
+ /// Simple escape for use in zsh single-quoted strings
+ TString S(TStringBuf string);
+ TString SS(TStringBuf string);
+
+ /// Simple escape for use in bash single-quoted strings
+ TString B(TStringBuf string);
+ TString BB(TStringBuf string);
+ }
+}