aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/getopt/small
diff options
context:
space:
mode:
authorbulatkhr <bulatkhr@yandex-team.com>2022-07-15 10:12:22 +0300
committerbulatkhr <bulatkhr@yandex-team.com>2022-07-15 10:12:22 +0300
commit03cf908feb326c966c4384fde4360f08d9b5b4e1 (patch)
tree29faaf859522f25ba29220000dac674ac364569a /library/cpp/getopt/small
parentb63fb26957f120f5cbf2a363d9fef60df2e7c2ae (diff)
downloadydb-03cf908feb326c966c4384fde4360f08d9b5b4e1.tar.gz
Allow skip arg in opt parser
add UnnecessaryArgument
Diffstat (limited to 'library/cpp/getopt/small')
-rw-r--r--library/cpp/getopt/small/last_getopt_opt.h18
-rw-r--r--library/cpp/getopt/small/last_getopt_parser.cpp2
2 files changed, 19 insertions, 1 deletions
diff --git a/library/cpp/getopt/small/last_getopt_opt.h b/library/cpp/getopt/small/last_getopt_opt.h
index a8dd5adca9..e8567bd4f6 100644
--- a/library/cpp/getopt/small/last_getopt_opt.h
+++ b/library/cpp/getopt/small/last_getopt_opt.h
@@ -62,6 +62,7 @@ namespace NLastGetopt {
EHasArg HasArg_ = DEFAULT_HAS_ARG; // the argument parsing politics
bool Required_ = false; // option existence politics
+ bool EqParseOnly_ = false; // allows option not to read argument
bool AllowMultipleCompletion_ = false; // let the completer know that this option can occur more than once
@@ -286,6 +287,23 @@ namespace NLastGetopt {
}
/**
+ * allow only --option=arg parsing and disable --option arg
+ * @return self
+ */
+ TOpt& DisableSpaceParse() {
+ Y_ASSERT(GetHasArg() == OPTIONAL_ARGUMENT);
+ EqParseOnly_ = true;
+ return *this;
+ }
+
+ /**
+ * @return true if only --option=arg parse allowed
+ */
+ bool IsEqParseOnly() const {
+ return EqParseOnly_;
+ }
+
+ /**
* sets the option to be optional
* @return self
*/
diff --git a/library/cpp/getopt/small/last_getopt_parser.cpp b/library/cpp/getopt/small/last_getopt_parser.cpp
index 7668b12a03..911c76f342 100644
--- a/library/cpp/getopt/small/last_getopt_parser.cpp
+++ b/library/cpp/getopt/small/last_getopt_parser.cpp
@@ -170,7 +170,7 @@ namespace NLastGetopt {
bool TOptsParser::ParseOptParam(const TOpt* opt, size_t pos) {
Y_ASSERT(opt);
- if (opt->GetHasArg() == NO_ARGUMENT) {
+ if (opt->GetHasArg() == NO_ARGUMENT || opt->IsEqParseOnly()) {
return Commit(opt, nullptr, pos, 0);
}
if (pos == Argc_) {