aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/getopt/small
diff options
context:
space:
mode:
authorAlexander Fokin <apfokin@gmail.com>2022-02-10 16:45:38 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:38 +0300
commit863a59a65247c24db7cb06789bc5cf79d04da32f (patch)
tree139dc000c8cd4a40f5659e421b7c75135d080307 /library/cpp/getopt/small
parentf64e95a9eb9ab03240599eb9581c5a9102426a96 (diff)
downloadydb-863a59a65247c24db7cb06789bc5cf79d04da32f.tar.gz
Restoring authorship annotation for Alexander Fokin <apfokin@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/getopt/small')
-rw-r--r--library/cpp/getopt/small/last_getopt.h38
-rw-r--r--library/cpp/getopt/small/last_getopt_easy_setup.h24
-rw-r--r--library/cpp/getopt/small/last_getopt_opt.h276
-rw-r--r--library/cpp/getopt/small/ya.make2
4 files changed, 170 insertions, 170 deletions
diff --git a/library/cpp/getopt/small/last_getopt.h b/library/cpp/getopt/small/last_getopt.h
index 07687bc914..0cf4ad803d 100644
--- a/library/cpp/getopt/small/last_getopt.h
+++ b/library/cpp/getopt/small/last_getopt.h
@@ -33,29 +33,29 @@ namespace NLastGetopt {
void HandleOpt(const TOptsParser* parser) override {
const TStringBuf curval(parser->CurValOrDef());
if (curval.IsInited()) {
- StringSplitter(curval).Split(ElementsDelim).Consume([&](const TStringBuf& val) {
- TStringBuf mutableValue = val;
+ StringSplitter(curval).Split(ElementsDelim).Consume([&](const TStringBuf& val) {
+ TStringBuf mutableValue = val;
- TValue first = NPrivate::OptFromString<TValue>(mutableValue.NextTok(RangesDelim), parser->CurOpt());
- TValue last = mutableValue ? NPrivate::OptFromString<TValue>(mutableValue, parser->CurOpt()) : first;
+ TValue first = NPrivate::OptFromString<TValue>(mutableValue.NextTok(RangesDelim), parser->CurOpt());
+ TValue last = mutableValue ? NPrivate::OptFromString<TValue>(mutableValue, parser->CurOpt()) : first;
- if (last < first) {
+ if (last < first) {
throw TUsageException() << "failed to parse opt " << NPrivate::OptToString(parser->CurOpt()) << " value " << TString(val).Quote() << ": the second argument is less than the first one";
- }
+ }
- for (++last; first < last; ++first) {
- Target->insert(Target->end(), first);
- }
- });
+ for (++last; first < last; ++first) {
+ Target->insert(Target->end(), first);
+ }
+ });
}
- }
+ }
- private:
- TContainer* Target;
+ private:
+ TContainer* Target;
char ElementsDelim;
char RangesDelim;
};
-
+
template <class Container>
struct TOptSplitHandler: public IOptHandler {
public:
@@ -67,13 +67,13 @@ namespace NLastGetopt {
, Delim(delim)
{
}
-
+
void HandleOpt(const TOptsParser* parser) override {
const TStringBuf curval(parser->CurValOrDef());
if (curval.IsInited()) {
- StringSplitter(curval).Split(Delim).Consume([&](const TStringBuf& val) {
- Target->insert(Target->end(), NPrivate::OptFromString<TValue>(val, parser->CurOpt()));
- });
+ StringSplitter(curval).Split(Delim).Consume([&](const TStringBuf& val) {
+ Target->insert(Target->end(), NPrivate::OptFromString<TValue>(val, parser->CurOpt()));
+ });
}
}
@@ -81,7 +81,7 @@ namespace NLastGetopt {
TContainer* Target;
char Delim;
};
-
+
template <class TpFunc>
struct TOptKVHandler: public IOptHandler {
public:
diff --git a/library/cpp/getopt/small/last_getopt_easy_setup.h b/library/cpp/getopt/small/last_getopt_easy_setup.h
index 60dddda225..3c8100d04d 100644
--- a/library/cpp/getopt/small/last_getopt_easy_setup.h
+++ b/library/cpp/getopt/small/last_getopt_easy_setup.h
@@ -4,18 +4,18 @@
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);
- */
+ * 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());
diff --git a/library/cpp/getopt/small/last_getopt_opt.h b/library/cpp/getopt/small/last_getopt_opt.h
index a8dd5adca9..f3489f896d 100644
--- a/library/cpp/getopt/small/last_getopt_opt.h
+++ b/library/cpp/getopt/small/last_getopt_opt.h
@@ -21,25 +21,25 @@ namespace NLastGetopt {
};
/**
- * NLastGetopt::TOpt is a storage of data about exactly one program option.
- * The data is: parse politics and help information.
- *
- * The help information consists of following:
- * hidden or visible in help information
- * help string
- * argument name
- *
- * Parse politics is determined by following parameters:
- * argument parse politics: no/optional/required/
- * option existence: required or optional
- * handlers. See detailed documentation: <TODO:link>
- * default value: if the option has argument, but the option is ommited,
- * then the <default value> is used as the value of the argument
- * optional value: if the option has optional-argument, the option is present in parsed string,
- * but the argument is omitted, then <optional value is used>
- * in case of "not given <optional value>, omited optional argument" the <default value> is used
- * user value: allows to store arbitary pointer for handlers
- */
+ * NLastGetopt::TOpt is a storage of data about exactly one program option.
+ * The data is: parse politics and help information.
+ *
+ * The help information consists of following:
+ * hidden or visible in help information
+ * help string
+ * argument name
+ *
+ * Parse politics is determined by following parameters:
+ * argument parse politics: no/optional/required/
+ * option existence: required or optional
+ * handlers. See detailed documentation: <TODO:link>
+ * default value: if the option has argument, but the option is ommited,
+ * then the <default value> is used as the value of the argument
+ * optional value: if the option has optional-argument, the option is present in parsed string,
+ * but the argument is omitted, then <optional value is used>
+ * in case of "not given <optional value>, omited optional argument" the <default value> is used
+ * user value: allows to store arbitary pointer for handlers
+ */
class TOpt {
public:
typedef TVector<char> TShortNames;
@@ -81,180 +81,180 @@ namespace NLastGetopt {
public:
/**
- * Checks if given char can be a short name
- * @param c char to check
- */
+ * Checks if given char can be a short name
+ * @param c char to check
+ */
static bool IsAllowedShortName(unsigned char c);
/**
- * Checks if given string can be a long name
- * @param name string to check
- * @param c if given, the first bad charecter will be saved in c
- */
+ * Checks if given string can be a long name
+ * @param name string to check
+ * @param c if given, the first bad charecter will be saved in c
+ */
static bool IsAllowedLongName(const TString& name, unsigned char* c = nullptr);
/**
- * @return one of the expected representations of the option.
- * If the option has short names, will return "-<char>"
- * Otherwise will return "--<long name>"
- */
+ * @return one of the expected representations of the option.
+ * If the option has short names, will return "-<char>"
+ * Otherwise will return "--<long name>"
+ */
TString ToShortString() const;
/**
- * check if given string is one of the long names
- *
- * @param name string to check
- */
+ * check if given string is one of the long names
+ *
+ * @param name string to check
+ */
bool NameIs(const TString& name) const;
/**
- * check if given char is one of the short names
- *
- * @param c char to check
- */
+ * check if given char is one of the short names
+ *
+ * @param c char to check
+ */
bool CharIs(char c) const;
/**
- * If string has long names - will return one of them
- * Otherwise will throw
- */
+ * If string has long names - will return one of them
+ * Otherwise will throw
+ */
TString GetName() const;
/**
- * adds short alias for the option
- *
- * @param c new short name
- *
- * @return self
- */
+ * adds short alias for the option
+ *
+ * @param c new short name
+ *
+ * @return self
+ */
TOpt& AddShortName(unsigned char c);
/**
- * return all short names of the option
- */
+ * return all short names of the option
+ */
const TShortNames& GetShortNames() const {
return Chars_;
}
/**
- * adds long alias for the option
- *
- * @param name new long name
- *
- * @return self
- */
+ * adds long alias for the option
+ *
+ * @param name new long name
+ *
+ * @return self
+ */
TOpt& AddLongName(const TString& name);
/**
- * return all long names of the option
- */
+ * return all long names of the option
+ */
const TLongNames& GetLongNames() const {
return LongNames_;
}
/**
- * @return one of short names of the opt. If there is no short names exception is raised.
- */
+ * @return one of short names of the opt. If there is no short names exception is raised.
+ */
char GetChar() const;
/**
- * @return one of short names of the opt. If there is no short names '\0' returned.
- */
+ * @return one of short names of the opt. If there is no short names '\0' returned.
+ */
char GetCharOr0() const;
/**
- * @returns argument parsing politics
- */
+ * @returns argument parsing politics
+ */
const EHasArg& GetHasArg() const {
return HasArg_;
}
/**
- * sets argument parsing politics
- *
- * Note: its better use one of RequiredArgument/NoArgument/OptionalArgument methods
- *
- * @param hasArg new argument parsing mode
- * @return self
- */
+ * sets argument parsing politics
+ *
+ * Note: its better use one of RequiredArgument/NoArgument/OptionalArgument methods
+ *
+ * @param hasArg new argument parsing mode
+ * @return self
+ */
TOpt& HasArg(EHasArg hasArg) {
HasArg_ = hasArg;
return *this;
}
/**
- * @returns argument title
- */
+ * @returns argument title
+ */
TString GetArgTitle() const {
return ArgTitle_;
}
/**
- * sets argument parsing politics into REQUIRED_ARGUMENT
- *
- * @param title the new name of argument in help output
- * @return self
- */
+ * sets argument parsing politics into REQUIRED_ARGUMENT
+ *
+ * @param title the new name of argument in help output
+ * @return self
+ */
TOpt& RequiredArgument(const TString& title = "") {
ArgTitle_ = title;
return HasArg(REQUIRED_ARGUMENT);
}
/**
- * sets argument parsing politics into NO_ARGUMENT
- *
- * @return self
- */
+ * sets argument parsing politics into NO_ARGUMENT
+ *
+ * @return self
+ */
TOpt& NoArgument() {
return HasArg(NO_ARGUMENT);
}
/**
- * sets argument parsing politics into OPTIONAL_ARGUMENT
- * for details see NLastGetopt::TOpt
- *
- * @param title the new name of argument in help output
- * @return self
- */
+ * sets argument parsing politics into OPTIONAL_ARGUMENT
+ * for details see NLastGetopt::TOpt
+ *
+ * @param title the new name of argument in help output
+ * @return self
+ */
TOpt& OptionalArgument(const TString& title = "") {
ArgTitle_ = title;
return HasArg(OPTIONAL_ARGUMENT);
}
/**
- * sets argument parsing politics into OPTIONAL_ARGUMENT
- * sets the <optional value> into given
- *
- * for details see NLastGetopt::TOpt
- *
- * @param val the new <optional value>
- * @param title the new name of argument in help output
- * @return self
- */
+ * sets argument parsing politics into OPTIONAL_ARGUMENT
+ * sets the <optional value> into given
+ *
+ * for details see NLastGetopt::TOpt
+ *
+ * @param val the new <optional value>
+ * @param title the new name of argument in help output
+ * @return self
+ */
TOpt& OptionalValue(const TString& val, const TString& title = "") {
OptionalValue_ = val;
return OptionalArgument(title);
}
/**
- * checks if "argument parsing politics" is OPTIONAL_ARGUMENT and the <optional value> is set.
- */
+ * checks if "argument parsing politics" is OPTIONAL_ARGUMENT and the <optional value> is set.
+ */
bool HasOptionalValue() const {
return OPTIONAL_ARGUMENT == HasArg_ && OptionalValue_;
}
/**
- * @return optional value
- * throws exception if optional value wasn't set
- */
+ * @return optional value
+ * throws exception if optional value wasn't set
+ */
const TString& GetOptionalValue() const {
return *OptionalValue_;
}
/**
- * sets <default value>
- * @return self
- */
+ * sets <default value>
+ * @return self
+ */
template <typename T>
TOpt& DefaultValue(const T& val) {
DefaultValue_ = ToString(val);
@@ -262,74 +262,74 @@ namespace NLastGetopt {
}
/**
- * checks if default value is set.
- */
+ * checks if default value is set.
+ */
bool HasDefaultValue() const {
return DefaultValue_.Defined();
}
/**
- * @return default value
- * throws exception if <default value> wasn't set
- */
+ * @return default value
+ * throws exception if <default value> wasn't set
+ */
const TString& GetDefaultValue() const {
return *DefaultValue_;
}
/**
- * sets the option to be required
- * @return self
- */
+ * sets the option to be required
+ * @return self
+ */
TOpt& Required() {
Required_ = true;
return *this;
}
/**
- * sets the option to be optional
- * @return self
- */
+ * sets the option to be optional
+ * @return self
+ */
TOpt& Optional() {
Required_ = false;
return *this;
}
/**
- * @return true if the option is required
- */
+ * @return true if the option is required
+ */
bool IsRequired() const {
return Required_;
}
/**
- * sets the option to be hidden (invisible in help)
- * @return self
- */
+ * sets the option to be hidden (invisible in help)
+ * @return self
+ */
TOpt& Hidden() {
Hidden_ = true;
return *this;
}
/**
- * @return true if the option is hidden
- */
+ * @return true if the option is hidden
+ */
bool IsHidden() const {
return Hidden_;
}
/**
- * sets the <user value>
- * @return self
- * for details see NLastGetopt::TOpt
- */
+ * sets the <user value>
+ * @return self
+ * for details see NLastGetopt::TOpt
+ */
TOpt& UserValue(const void* userval) {
UserValue_ = userval;
return *this;
}
/**
- * @return user value
- */
+ * @return user value
+ */
const void* UserValue() const {
return UserValue_;
}
@@ -366,7 +366,7 @@ namespace NLastGetopt {
*
* See more on completion descriptions codestyle:
* https://github.com/zsh-users/zsh/blob/master/Etc/completion-style-guide#L43
- */
+ */
TOpt& Help(const TString& help) {
Help_ = help;
return *this;
@@ -374,7 +374,7 @@ namespace NLastGetopt {
/**
* Get help string.
- */
+ */
const TString& GetHelp() const {
return Help_;
}
@@ -395,7 +395,7 @@ namespace NLastGetopt {
* --help -h -- print help message and exit
* --timeout -t -- specify query timeout
* ```
- */
+ */
TOpt& CompletionHelp(const TString& help) {
CompletionHelp_ = help;
return *this;
@@ -707,13 +707,13 @@ namespace NLastGetopt {
};
/**
- * NLastGetopt::TFreeArgSpec is a storage of data about free argument.
- * The data is help information and (maybe) linked named argument.
- *
- * The help information consists of following:
- * help string
- * argument name (title)
- */
+ * NLastGetopt::TFreeArgSpec is a storage of data about free argument.
+ * The data is help information and (maybe) linked named argument.
+ *
+ * The help information consists of following:
+ * help string
+ * argument name (title)
+ */
struct TFreeArgSpec {
TFreeArgSpec() = default;
TFreeArgSpec(const TString& title, const TString& help = TString(), bool optional = false)
diff --git a/library/cpp/getopt/small/ya.make b/library/cpp/getopt/small/ya.make
index 96de0f04b1..106adcaf80 100644
--- a/library/cpp/getopt/small/ya.make
+++ b/library/cpp/getopt/small/ya.make
@@ -5,7 +5,7 @@ OWNER(pg)
PEERDIR(
library/cpp/colorizer
)
-
+
SRCS(
completer.cpp
completer_command.cpp