aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/getopt/small/modchooser.h
diff options
context:
space:
mode:
authorsteplg <steplg@yandex-team.ru>2022-02-10 16:50:54 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:54 +0300
commit18b9863882c0f9638e4a6599acbcdfe6109d5da0 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/getopt/small/modchooser.h
parentd385578a0e719dc19758dbdef4ca862726ce22a7 (diff)
downloadydb-18b9863882c0f9638e4a6599acbcdfe6109d5da0.tar.gz
Restoring authorship annotation for <steplg@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/getopt/small/modchooser.h')
-rw-r--r--library/cpp/getopt/small/modchooser.h104
1 files changed, 52 insertions, 52 deletions
diff --git a/library/cpp/getopt/small/modchooser.h b/library/cpp/getopt/small/modchooser.h
index 8abdd531d02..0a8de6d50b5 100644
--- a/library/cpp/getopt/small/modchooser.h
+++ b/library/cpp/getopt/small/modchooser.h
@@ -1,59 +1,59 @@
-#pragma once
-
+#pragma once
+
#include "last_getopt_opts.h"
#include <util/generic/map.h>
#include <util/generic/string.h>
-#include <util/generic/vector.h>
-
+#include <util/generic/vector.h>
+
#include <functional>
-//! Mode function with vector of cli arguments.
+//! Mode function with vector of cli arguments.
using TMainFunctionPtrV = std::function<int(const TVector<TString>&)> ;
using TMainFunctionRawPtrV = int (*)(const TVector<TString>& argv);
-
-//! Mode function with classic argc and argv arguments.
+
+//! Mode function with classic argc and argv arguments.
using TMainFunctionPtr = std::function<int(int, const char**)> ;
using TMainFunctionRawPtr = int (*)(const int argc, const char** argv);
-
-//! Mode class with vector of cli arguments.
-class TMainClassV {
-public:
+
+//! Mode class with vector of cli arguments.
+class TMainClassV {
+public:
virtual int operator()(const TVector<TString>& argv) = 0;
virtual ~TMainClassV() = default;
-};
-
-//! Mode class with classic argc and argv arguments.
-class TMainClass {
-public:
+};
+
+//! Mode class with classic argc and argv arguments.
+class TMainClass {
+public:
virtual int operator()(int argc, const char** argv) = 0;
virtual ~TMainClass() = default;
-};
-
+};
+
//! Function to handle '--version' parameter
typedef void (*TVersionHandlerPtr)();
-/*! Main class for handling different modes in single tool.
+/*! Main class for handling different modes in single tool.
*
- * You can add modes for this class, use autogenerated help with
- * list of modes and automaticly call necessary mode in run().
- *
- * In first argv element mode get joined by space tool name and
- * current mode name.
- */
-class TModChooser {
-public:
+ * You can add modes for this class, use autogenerated help with
+ * list of modes and automaticly call necessary mode in run().
+ *
+ * In first argv element mode get joined by space tool name and
+ * current mode name.
+ */
+class TModChooser {
+public:
TModChooser();
- ~TModChooser();
+ ~TModChooser();
-public:
+public:
void AddMode(const TString& mode, TMainFunctionRawPtr func, const TString& description, bool hidden = false, bool noCompletion = false);
void AddMode(const TString& mode, TMainFunctionRawPtrV func, const TString& description, bool hidden = false, bool noCompletion = false);
void AddMode(const TString& mode, TMainFunctionPtr func, const TString& description, bool hidden = false, bool noCompletion = false);
void AddMode(const TString& mode, TMainFunctionPtrV func, const TString& description, bool hidden = false, bool noCompletion = false);
void AddMode(const TString& mode, TMainClass* func, const TString& description, bool hidden = false, bool noCompletion = false);
void AddMode(const TString& mode, TMainClassV* func, const TString& description, bool hidden = false, bool noCompletion = false);
-
+
//! Hidden groups won't be displayed in 'help' block
void AddGroupModeDescription(const TString& description, bool hidden = false, bool noCompletion = false);
@@ -62,9 +62,9 @@ public:
void AddAlias(const TString& alias, const TString& mode);
- //! Set main program description.
+ //! Set main program description.
void SetDescription(const TString& descr);
-
+
//! Set modes help option name (-? is by default)
void SetModesHelpOption(const TString& helpOption);
@@ -84,32 +84,32 @@ public:
void AddCompletions(TString progName, const TString& name = "completion", bool hidden = false, bool noCompletion = false);
- /*! Run appropriate mode.
- *
+ /*! Run appropriate mode.
+ *
* In this method following things happen:
- * 1) If first argument is -h/--help/-? then print short description of
- * all modes and exit with zero code.
+ * 1) If first argument is -h/--help/-? then print short description of
+ * all modes and exit with zero code.
* 2) If first argument is -v/--version and version handler is specified,
* then call it and exit with zero code.
* 3) Find mode with the same name as first argument. If it's found then
* call it and return its return code.
* 4) If appropriate mode is not found - return non-zero code.
- */
+ */
int Run(int argc, const char** argv) const;
-
- //! Run appropriate mode. Same as Run(const int, const char**)
+
+ //! Run appropriate mode. Same as Run(const int, const char**)
int Run(const TVector<TString>& argv) const;
-
+
void PrintHelp(const TString& progName) const;
-
- struct TMode {
+
+ struct TMode {
TString Name;
TMainClass* Main;
TString Description;
bool Hidden;
bool NoCompletion;
TVector<TString> Aliases;
-
+
TMode()
: Main(nullptr)
{
@@ -120,8 +120,8 @@ public:
// Full name includes primary name and aliases. Also, will add ANSI colors.
size_t CalculateFullNameLen() const;
TString FormatFullName(size_t pad) const;
- };
-
+ };
+
TVector<const TMode*> GetUnsortedModes() const {
auto ret = TVector<const TMode*>(Reserve(UnsortedModes.size()));
for (auto& mode : UnsortedModes) {
@@ -129,22 +129,22 @@ public:
}
return ret;
}
-
+
TVersionHandlerPtr GetVersionHandler() const;
bool IsSvnRevisionOptionDisabled() const;
-private:
- //! Main program description.
+private:
+ //! Main program description.
TString Description;
-
+
//! Help option for modes.
TString ModesHelpOption;
//! Wrappers around all modes.
TVector<THolder<TMainClass>> Wrappers;
-
- //! Modes
+
+ //! Modes
TMap<TString, TMode*> Modes;
TString DefaultMode;
@@ -169,7 +169,7 @@ private:
//! Mode that generates completions
THolder<TMainClass> CompletionsGenerator;
-};
+};
//! Mode class that allows introspecting its console arguments.
class TMainClassArgs: public TMainClass {