aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/getopt/small/last_getopt_opts.h
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/getopt/small/last_getopt_opts.h
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
downloadydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/getopt/small/last_getopt_opts.h')
-rw-r--r--library/cpp/getopt/small/last_getopt_opts.h340
1 files changed, 170 insertions, 170 deletions
diff --git a/library/cpp/getopt/small/last_getopt_opts.h b/library/cpp/getopt/small/last_getopt_opts.h
index 825b99c871..f7469ea313 100644
--- a/library/cpp/getopt/small/last_getopt_opts.h
+++ b/library/cpp/getopt/small/last_getopt_opts.h
@@ -7,14 +7,14 @@
#include <util/generic/map.h>
namespace NLastGetopt {
- enum EArgPermutation {
- REQUIRE_ORDER,
- PERMUTE,
- RETURN_IN_ORDER,
- DEFAULT_ARG_PERMUTATION = PERMUTE
- };
-
- /**
+ enum EArgPermutation {
+ REQUIRE_ORDER,
+ PERMUTE,
+ RETURN_IN_ORDER,
+ DEFAULT_ARG_PERMUTATION = PERMUTE
+ };
+
+ /**
* NLastGetopt::TOpts is a storage of program options' parse rules.
* It contains information about all options, free args, some parsing options
* and rules about interaction between options.
@@ -34,96 +34,96 @@ namespace NLastGetopt {
* - Allowing unknown options
*
*/
- class TOpts {
- friend class TOptsParseResult;
- friend class TOptsParser;
+ class TOpts {
+ friend class TOptsParseResult;
+ friend class TOptsParser;
- public:
+ public:
static constexpr const ui32 UNLIMITED_ARGS = Max<ui32>();
- typedef TVector<TSimpleSharedPtr<TOpt>> TOptsVector;
- TOptsVector Opts_; // infomation about named (short and long) options
+ typedef TVector<TSimpleSharedPtr<TOpt>> TOptsVector;
+ TOptsVector Opts_; // infomation about named (short and long) options
TVector<std::function<void(TStringBuf)>> ArgBindings_;
- EArgPermutation ArgPermutation_ = DEFAULT_ARG_PERMUTATION; // determines how to parse positions of named and free options. See information below.
- bool AllowSingleDashForLong_ = false; //
- bool AllowPlusForLong_ = false; // using '+' instead '--' for long options
+ EArgPermutation ArgPermutation_ = DEFAULT_ARG_PERMUTATION; // determines how to parse positions of named and free options. See information below.
+ bool AllowSingleDashForLong_ = false; //
+ bool AllowPlusForLong_ = false; // using '+' instead '--' for long options
- //Allows unknwon options:
- bool AllowUnknownCharOptions_ = false;
- bool AllowUnknownLongOptions_ = false;
+ //Allows unknwon options:
+ bool AllowUnknownCharOptions_ = false;
+ bool AllowUnknownLongOptions_ = false;
ui32 Wrap_ = 80;
- private:
- ui32 FreeArgsMin_; // minimal number of free args
- ui32 FreeArgsMax_; // maximal number of free args
+ private:
+ ui32 FreeArgsMin_; // minimal number of free args
+ ui32 FreeArgsMax_; // maximal number of free args
TMap<ui32, TFreeArgSpec> FreeArgSpecs_; // mapping [free arg position] -> [free arg specification]
TFreeArgSpec TrailingArgSpec_; // spec for the trailing argument (when arguments are unlimited)
TString DefaultFreeArgTitle_ = "ARG"; // title that's used for free args without a title
- TString Title; // title of the help string
- TString CustomCmdLineDescr; // user defined help string
+ TString Title; // title of the help string
+ TString CustomCmdLineDescr; // user defined help string
TString CustomUsage; // user defined usage string
TVector<std::pair<TString, TString>> Sections; // additional help entries to print after usage
- public:
- /**
+ public:
+ /**
* Constructs TOpts from string as in getopt(3)
*/
- TOpts(const TStringBuf& optstring = TStringBuf());
+ TOpts(const TStringBuf& optstring = TStringBuf());
- /**
+ /**
* Constructs TOpts from string as in getopt(3) and
* additionally adds help option (for '?') and svn-verstion option (for 'V')
*/
- static TOpts Default(const TStringBuf& optstring = TStringBuf()) {
- TOpts opts(optstring);
- opts.AddHelpOption();
- opts.AddVersionOption();
- return opts;
- }
+ static TOpts Default(const TStringBuf& optstring = TStringBuf()) {
+ TOpts opts(optstring);
+ opts.AddHelpOption();
+ opts.AddVersionOption();
+ return opts;
+ }
- /**
+ /**
* Checks correctness of options' descriptions.
* Throws TConfException if validation failed.
* Check consist of:
* -not intersecting of names
* -compability of settings, that responsable for freeArgs parsing
*/
- void Validate() const;
+ void Validate() const;
- /**
+ /**
* Search for the option with given long name
* @param name long name for search
* @return ptr on result (nullptr if not found)
*/
- const TOpt* FindLongOption(const TStringBuf& name) const;
+ const TOpt* FindLongOption(const TStringBuf& name) const;
- /**
+ /**
* Search for the option with given short name
* @param c short name for search
* @return ptr on result (nullptr if not found)
*/
- const TOpt* FindCharOption(char c) const;
+ const TOpt* FindCharOption(char c) const;
- /**
+ /**
* Search for the option with given long name
* @param name long name for search
* @return ptr on result (nullptr if not found)
*/
- TOpt* FindLongOption(const TStringBuf& name);
+ TOpt* FindLongOption(const TStringBuf& name);
- /**
+ /**
* Search for the option with given short name
* @param c short name for search
* @return ptr on result (nullptr if not found)
*/
- TOpt* FindCharOption(char c);
+ TOpt* FindCharOption(char c);
- /**
+ /**
* Search for the option with given name
* @param name name for search
* @return ptr on result (nullptr if not found)
@@ -152,57 +152,57 @@ namespace NLastGetopt {
* Sets title of the help string
* @param title title to set
*/
- void SetTitle(const TString& title) {
- Title = title;
- }
+ void SetTitle(const TString& title) {
+ Title = title;
+ }
- /**
+ /**
* @return true if there is an option with given long name
*
* @param name long name for search
*/
- bool HasLongOption(const TString& name) const {
- return FindLongOption(name) != nullptr;
- }
+ bool HasLongOption(const TString& name) const {
+ return FindLongOption(name) != nullptr;
+ }
- /**
+ /**
* @return true if there is an option with given short name
*
* @param char short name for search
*/
- bool HasCharOption(char c) const {
- return FindCharOption(c) != nullptr;
- }
+ bool HasCharOption(char c) const {
+ return FindCharOption(c) != nullptr;
+ }
- /**
+ /**
* Search for the option with given long name
* @param name long name for search
* @return ref on result (throw exception if not found)
*/
- const TOpt& GetLongOption(const TStringBuf& name) const;
+ const TOpt& GetLongOption(const TStringBuf& name) const;
- /**
+ /**
* Search for the option with given long name
* @param name long name for search
* @return ref on result (throw exception if not found)
*/
- TOpt& GetLongOption(const TStringBuf& name);
+ TOpt& GetLongOption(const TStringBuf& name);
- /**
+ /**
* Search for the option with given short name
* @param c short name for search
* @return ref on result (throw exception if not found)
*/
- const TOpt& GetCharOption(char c) const;
+ const TOpt& GetCharOption(char c) const;
- /**
+ /**
* Search for the option with given short name
* @param c short name for search
* @return ref on result (throw exception if not found)
*/
- TOpt& GetCharOption(char c);
+ TOpt& GetCharOption(char c);
- /**
+ /**
* Search for the option with given name
* @param name name for search
* @return ref on result (throw exception if not found)
@@ -230,21 +230,21 @@ namespace NLastGetopt {
/**
* @return true if short options exist
*/
- bool HasAnyShortOption() const;
+ bool HasAnyShortOption() const;
- /**
+ /**
* @return true if long options exist
*/
- bool HasAnyLongOption() const;
+ bool HasAnyLongOption() const;
- /**
+ /**
* Creates new [option description (TOpt)] as a copy of given one
* @param option source
* @return reference for created option
*/
- TOpt& AddOption(const TOpt& option);
+ TOpt& AddOption(const TOpt& option);
- /**
+ /**
* Creates new free argument handling
* @param name name of free arg to show in help
* @param target variable address to store parsing result into
@@ -265,46 +265,46 @@ namespace NLastGetopt {
*
* @param optstring source
*/
- void AddCharOptions(const TStringBuf& optstring);
+ void AddCharOptions(const TStringBuf& optstring);
- /**
+ /**
* Creates new [option description (TOpt)] with given short name and given help string
*
* @param c short name
* @param help help string
* @return reference for created option
*/
- TOpt& AddCharOption(char c, const TString& help = "") {
- return AddCharOption(c, DEFAULT_HAS_ARG, help);
- }
+ TOpt& AddCharOption(char c, const TString& help = "") {
+ return AddCharOption(c, DEFAULT_HAS_ARG, help);
+ }
- /**
+ /**
* Creates new [option description (TOpt)] with given short name and given help string
*
* @param c short name
* @param help help string
* @return reference for created option
*/
- TOpt& AddCharOption(char c, EHasArg hasArg, const TString& help = "") {
- TOpt option;
- option.AddShortName(c);
- option.Help(help);
- option.HasArg(hasArg);
- return AddOption(option);
- }
+ TOpt& AddCharOption(char c, EHasArg hasArg, const TString& help = "") {
+ TOpt option;
+ option.AddShortName(c);
+ option.Help(help);
+ option.HasArg(hasArg);
+ return AddOption(option);
+ }
- /**
+ /**
* Creates new [option description (TOpt)] with given long name and given help string
*
* @param name long name
* @param help help string
* @return reference for created option
*/
- TOpt& AddLongOption(const TString& name, const TString& help = "") {
- return AddLongOption(0, name, help);
- }
+ TOpt& AddLongOption(const TString& name, const TString& help = "") {
+ return AddLongOption(0, name, help);
+ }
- /**
+ /**
* Creates new [option description (TOpt)] with given long and short names and given help string
*
* @param c short name
@@ -312,54 +312,54 @@ namespace NLastGetopt {
* @param help help string
* @return reference for created option
*/
- TOpt& AddLongOption(char c, const TString& name, const TString& help = "") {
- TOpt option;
- if (c != 0)
- option.AddShortName(c);
- option.AddLongName(name);
- option.Help(help);
- return AddOption(option);
- }
+ TOpt& AddLongOption(char c, const TString& name, const TString& help = "") {
+ TOpt option;
+ if (c != 0)
+ option.AddShortName(c);
+ option.AddLongName(name);
+ option.Help(help);
+ return AddOption(option);
+ }
- /**
+ /**
* Creates new [option description (TOpt)] for help printing,
* adds appropriate handler for it
* If "help" option already exist, will add given short name to it.
*
* @param c new short name for help option
*/
- TOpt& AddHelpOption(char c = '?') {
- if (TOpt* o = FindLongOption("help")) {
- if (!o->CharIs(c))
- o->AddShortName(c);
- return *o;
- }
- return AddLongOption(c, "help", "print usage")
- .HasArg(NO_ARGUMENT)
+ TOpt& AddHelpOption(char c = '?') {
+ if (TOpt* o = FindLongOption("help")) {
+ if (!o->CharIs(c))
+ o->AddShortName(c);
+ return *o;
+ }
+ return AddLongOption(c, "help", "print usage")
+ .HasArg(NO_ARGUMENT)
.IfPresentDisableCompletion()
- .Handler(&PrintUsageAndExit);
+ .Handler(&PrintUsageAndExit);
}
- /**
+ /**
* Creates new [option description (TOpt)] for svn-revision printing,
* adds appropriate handler for it.
* If "svnversion" option already exist, will add given short name to it.
*
* @param c new short name for "svnversion" option
*/
- TOpt& AddVersionOption(char c = 'V') {
- if (TOpt* o = FindLongOption("svnrevision")) {
- if (!o->CharIs(c))
- o->AddShortName(c);
- return *o;
- }
- return AddLongOption(c, "svnrevision", "print svn version")
- .HasArg(NO_ARGUMENT)
+ TOpt& AddVersionOption(char c = 'V') {
+ if (TOpt* o = FindLongOption("svnrevision")) {
+ if (!o->CharIs(c))
+ o->AddShortName(c);
+ return *o;
+ }
+ return AddLongOption(c, "svnrevision", "print svn version")
+ .HasArg(NO_ARGUMENT)
.IfPresentDisableCompletion()
- .Handler(&PrintVersionAndExit);
+ .Handler(&PrintVersionAndExit);
}
- /**
+ /**
* Creates new option for generating completion shell scripts.
*
* @param command name of command that should be completed (typically corresponds to the executable name).
@@ -371,17 +371,17 @@ namespace NLastGetopt {
*
* @param c new short name for search/create
*/
- TOpt& CharOption(char c) {
- const TOpt* opt = FindCharOption(c);
- if (opt != nullptr) {
- return const_cast<TOpt&>(*opt);
- } else {
- AddCharOption(c);
- return const_cast<TOpt&>(GetCharOption(c));
- }
+ TOpt& CharOption(char c) {
+ const TOpt* opt = FindCharOption(c);
+ if (opt != nullptr) {
+ return const_cast<TOpt&>(*opt);
+ } else {
+ AddCharOption(c);
+ return const_cast<TOpt&>(GetCharOption(c));
+ }
}
- /**
+ /**
* Indicate that some options can't appear together.
*
* Note: this is not transitive.
@@ -404,18 +404,18 @@ namespace NLastGetopt {
*
* @param opt pointer of option to search
*/
- size_t IndexOf(const TOpt* opt) const;
+ size_t IndexOf(const TOpt* opt) const;
- /**
+ /**
* Replace help string with given
*
* @param decr new help string
*/
- void SetCmdLineDescr(const TString& descr) {
- CustomCmdLineDescr = descr;
- }
+ void SetCmdLineDescr(const TString& descr) {
+ CustomCmdLineDescr = descr;
+ }
- /**
+ /**
* Replace usage string with given
*
* @param usage new usage string
@@ -445,12 +445,12 @@ namespace NLastGetopt {
*
* @param min new value
*/
- void SetFreeArgsMin(size_t min) {
- FreeArgsMin_ = ui32(min);
- }
+ void SetFreeArgsMin(size_t min) {
+ FreeArgsMin_ = ui32(min);
+ }
- /**
+ /**
* Get current minimal number of free args
*/
ui32 GetFreeArgsMin() const {
@@ -462,12 +462,12 @@ namespace NLastGetopt {
*
* @param max new value
*/
- void SetFreeArgsMax(size_t max) {
- FreeArgsMax_ = ui32(max);
+ void SetFreeArgsMax(size_t max) {
+ FreeArgsMax_ = ui32(max);
FreeArgsMax_ = Max<ui32>(FreeArgsMax_, ArgBindings_.size());
- }
+ }
- /**
+ /**
* Get current maximal number of free args
*/
ui32 GetFreeArgsMax() const {
@@ -486,23 +486,23 @@ namespace NLastGetopt {
*
* @param count new value
*/
- void SetFreeArgsNum(size_t count) {
- FreeArgsMin_ = ui32(count);
- FreeArgsMax_ = ui32(count);
- }
+ void SetFreeArgsNum(size_t count) {
+ FreeArgsMin_ = ui32(count);
+ FreeArgsMax_ = ui32(count);
+ }
- /**
+ /**
* Set minimal and maximal number of free args
*
* @param min new value for minimal
* @param max new value for maximal
*/
- void SetFreeArgsNum(size_t min, size_t max) {
- FreeArgsMin_ = ui32(min);
- FreeArgsMax_ = ui32(max);
- }
+ void SetFreeArgsNum(size_t min, size_t max) {
+ FreeArgsMin_ = ui32(min);
+ FreeArgsMax_ = ui32(max);
+ }
- /**
+ /**
* Set title and help string of free argument
*
* @param pos index of argument
@@ -513,7 +513,7 @@ namespace NLastGetopt {
*/
void SetFreeArgTitle(size_t pos, const TString& title, const TString& help = TString(), bool optional = false);
- /**
+ /**
* Get free argument's spec for further modification.
*/
TFreeArgSpec& GetFreeArgSpec(size_t pos);
@@ -556,7 +556,7 @@ namespace NLastGetopt {
}
/// @}
- /**
+ /**
* Get spec for the trailing argument.
*
* This spec is used to render the last repeated argument when max number of arguments is unlimited.
@@ -575,11 +575,11 @@ namespace NLastGetopt {
*
* @param value new value of the option
*/
- void SetAllowSingleDashForLong(bool value) {
- AllowSingleDashForLong_ = value;
- }
+ void SetAllowSingleDashForLong(bool value) {
+ AllowSingleDashForLong_ = value;
+ }
- /**
+ /**
* Wrap help text at this number of characters. 0 to disable wrapping.
*/
void SetWrap(ui32 wrap = 80) {
@@ -593,17 +593,17 @@ namespace NLastGetopt {
* @param os destination stream
* @param colors colorizer
*/
- void PrintUsage(const TStringBuf& program, IOutputStream& os, const NColorizer::TColors& colors) const;
+ void PrintUsage(const TStringBuf& program, IOutputStream& os, const NColorizer::TColors& colors) const;
- /**
+ /**
* Print usage string
*
* @param program prefix of result (path to the program)
* @param os destination stream
*/
- void PrintUsage(const TStringBuf& program, IOutputStream& os = Cout) const;
-
- /**
+ void PrintUsage(const TStringBuf& program, IOutputStream& os = Cout) const;
+
+ /**
* Get list of options in order of definition.
*/
TVector<const TOpt*> GetOpts() const {
@@ -615,29 +615,29 @@ namespace NLastGetopt {
}
private:
- /**
+ /**
* @return argument title of a free argument
*
* @param pos position of the argument
*/
TStringBuf GetFreeArgTitle(size_t pos) const;
- /**
+ /**
* Print usage helper
*
* @param program prefix of result (path to the program)
* @param os destination stream
* @param colors colorizer
*/
- void PrintCmdLine(const TStringBuf& program, IOutputStream& os, const NColorizer::TColors& colors) const;
+ void PrintCmdLine(const TStringBuf& program, IOutputStream& os, const NColorizer::TColors& colors) const;
- /**
+ /**
* Print usage helper
*
* @param os destination stream
* @param colors colorizer
*/
- void PrintFreeArgsDesc(IOutputStream& os, const NColorizer::TColors& colors) const;
- };
+ void PrintFreeArgsDesc(IOutputStream& os, const NColorizer::TColors& colors) const;
+ };
-}
+}