aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/getopt/small/last_getopt_easy_setup.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/last_getopt_easy_setup.h
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/getopt/small/last_getopt_easy_setup.h')
-rw-r--r--library/cpp/getopt/small/last_getopt_easy_setup.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/library/cpp/getopt/small/last_getopt_easy_setup.h b/library/cpp/getopt/small/last_getopt_easy_setup.h
new file mode 100644
index 0000000000..60dddda225
--- /dev/null
+++ b/library/cpp/getopt/small/last_getopt_easy_setup.h
@@ -0,0 +1,51 @@
+#pragma once
+
+#include "last_getopt_opts.h"
+
+namespace NLastGetopt {
+ /**
+ * Wrapper for TOpts class to make the life a bit easier.
+ * Usual usage:
+ * TEasySetup opts;
+ * opts('s', "server", "MR_SERVER", "MapReduce server name in format server:port", true)
+ * ('u', "user", "MR_USER", "MapReduce user name", true)
+ * ('o', "output", "MR_TABLE", "Name of MR table which will contain results", true)
+ * ('r', "rules", "FILE", "Filename for .rules output file") //!< This parameter is optional and has a required argument
+ * ('v', "version", &PrintSvnVersionAndExit0, "Print version information") //!< Parameter with handler can't get any argument
+ * ("verbose", "Be verbose") //!< You may not specify short param name
+ *
+ * NLastGetopt::TOptsParseResult r(&opts, argc, argv);
+ */
+ class TEasySetup: public TOpts {
+ public:
+ TEasySetup(const TStringBuf& optstring = TStringBuf());
+ TEasySetup& operator()(char shortName, const char* longName, const char* help, bool required = false);
+ TEasySetup& operator()(char shortName, const char* longName, const char* argName, const char* help, bool required = false);
+
+ template <class TpFunc>
+ TEasySetup& operator()(char shortName, const char* longName, TpFunc handler, const char* help, bool required = false) {
+ AdjustParam(longName, help, nullptr, handler, required).AddShortName(shortName);
+ return *this;
+ }
+
+ TEasySetup& operator()(const char* longName, const char* help, bool required = false);
+ TEasySetup& operator()(const char* longName, const char* argName, const char* help, bool required = false);
+
+ template <class TpFunc>
+ TEasySetup& operator()(const char* longName, TpFunc handler, const char* help, bool required = false) {
+ AdjustParam(longName, help, nullptr, handler, required);
+ return *this;
+ }
+
+ private:
+ TOpt& AdjustParam(const char* longName, const char* help, const char* argName, bool required);
+
+ template <class TpFunc>
+ TOpt& AdjustParam(const char* longName, const char* help, const char* argName, TpFunc handler, bool required) {
+ TOpt& o = AdjustParam(longName, help, argName, required);
+ o.Handler0(handler);
+ return o;
+ }
+ };
+
+}