diff options
author | Alexander Smirnov <alex@ydb.tech> | 2024-11-22 09:21:01 +0000 |
---|---|---|
committer | Alexander Smirnov <alex@ydb.tech> | 2024-11-22 09:21:01 +0000 |
commit | a7cac42c868ca5722777ccee944217410812e72c (patch) | |
tree | 7bff7ce2a3ade72f6f15dfc634490d13628066ee /library/cpp | |
parent | a18f18d81996ca8e681bb6cabd441b52833d99bf (diff) | |
parent | 9478cfdab4217d3710b96329466825bf47111d7d (diff) | |
download | ydb-a7cac42c868ca5722777ccee944217410812e72c.tar.gz |
Merge branch 'rightlib' into mergelibs-241122-0919
Diffstat (limited to 'library/cpp')
-rw-r--r-- | library/cpp/getopt/small/last_getopt_parse_result.h | 16 | ||||
-rw-r--r-- | library/cpp/getopt/small/last_getopt_parser.cpp | 7 | ||||
-rw-r--r-- | library/cpp/getopt/ut/last_getopt_ut.cpp | 13 |
3 files changed, 27 insertions, 9 deletions
diff --git a/library/cpp/getopt/small/last_getopt_parse_result.h b/library/cpp/getopt/small/last_getopt_parse_result.h index c6e768c461..f9ffaf0ab3 100644 --- a/library/cpp/getopt/small/last_getopt_parse_result.h +++ b/library/cpp/getopt/small/last_getopt_parse_result.h @@ -192,7 +192,7 @@ namespace NLastGetopt { bool Has(const TOpt* opt, bool includeDefault = false) const; /** - * @return nil terminated string on the last fetched argument of givne option + * @return nil terminated string on the last fetched argument of given option * * @param opt ptr on required object * @param includeDefault search in results obtained from default values @@ -200,7 +200,7 @@ namespace NLastGetopt { const char* Get(const TOpt* opt, bool includeDefault = true) const; /** - * @return nil terminated string on the last fetched argument of givne option + * @return nil terminated string on the last fetched argument of given option * if option haven't been fetched, given defaultValue will be returned * * @param opt ptr on required object @@ -218,7 +218,7 @@ namespace NLastGetopt { bool Has(const TString& name, bool includeDefault = false) const; /** - * @return nil terminated string on the last fetched argument of givne option + * @return nil terminated string on the last fetched argument of given option * * @param name long name of required object * @param includeDefault search in results obtained from default values @@ -226,7 +226,7 @@ namespace NLastGetopt { const char* Get(const TString& name, bool includeDefault = true) const; /** - * @return nil terminated string on the last fetched argument of givne option + * @return nil terminated string on the last fetched argument of given option * if option haven't been fetched, given defaultValue will be returned * * @param name long name of required object @@ -244,7 +244,7 @@ namespace NLastGetopt { bool Has(char name, bool includeDefault = false) const; /** - * @return nil terminated string on the last fetched argument of givne option + * @return nil terminated string on the last fetched argument of given option * * @param c short name of required object * @param includeDefault search in results obtained from default values @@ -252,7 +252,7 @@ namespace NLastGetopt { const char* Get(char name, bool includeDefault = true) const; /** - * @return nil terminated string on the last fetched argument of givne option + * @return nil terminated string on the last fetched argument of given option * if option haven't been fetched, given defaultValue will be returned * * @param c short name of required object @@ -261,7 +261,7 @@ namespace NLastGetopt { const char* GetOrElse(char name, const char* defaultValue) const; /** - * for givne option return parsed value of the last fetched argument + * for given option return parsed value of the last fetched argument * if option haven't been fetched, HandleError action is called * * @param opt required option (one of: ptr, short name, long name). @@ -280,7 +280,7 @@ namespace NLastGetopt { } /** - * for givne option return parsed value of the last fetched argument + * for given option return parsed value of the last fetched argument * if option haven't been fetched, given defaultValue will be returned * * @param opt required option (one of: ptr, short name, long name). diff --git a/library/cpp/getopt/small/last_getopt_parser.cpp b/library/cpp/getopt/small/last_getopt_parser.cpp index 911c76f342..98c3951a1c 100644 --- a/library/cpp/getopt/small/last_getopt_parser.cpp +++ b/library/cpp/getopt/small/last_getopt_parser.cpp @@ -170,9 +170,14 @@ namespace NLastGetopt { bool TOptsParser::ParseOptParam(const TOpt* opt, size_t pos) { Y_ASSERT(opt); - if (opt->GetHasArg() == NO_ARGUMENT || opt->IsEqParseOnly()) { + if (opt->GetHasArg() == NO_ARGUMENT || + opt->GetHasArg() == OPTIONAL_ARGUMENT && opt->IsEqParseOnly()) { return Commit(opt, nullptr, pos, 0); } + if (opt->IsEqParseOnly()) { + Y_ASSERT(opt->GetHasArg() == REQUIRED_ARGUMENT); + throw TUsageException() << "option " << opt->ToShortString() << " requires an argument but only accepts it over ="; + } if (pos == Argc_) { if (opt->GetHasArg() == REQUIRED_ARGUMENT) throw TUsageException() << "option " << opt->ToShortString() << " must have arg"; diff --git a/library/cpp/getopt/ut/last_getopt_ut.cpp b/library/cpp/getopt/ut/last_getopt_ut.cpp index b517ea359d..8fc9b7ef16 100644 --- a/library/cpp/getopt/ut/last_getopt_ut.cpp +++ b/library/cpp/getopt/ut/last_getopt_ut.cpp @@ -449,6 +449,19 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { tester.AcceptEndOfFreeArgs(); } + Y_UNIT_TEST(TestEqParseOnlyRequiredArgument) { + TOptsNoDefault opts; + + opts.AddLongOption("eq-only").RequiredArgument().DisableSpaceParse(); + + TOptsParseResultTestWrapper res(&opts, V({"cmd", "--eq-only=value"})); + UNIT_ASSERT_EQUAL(res.Get("eq-only"), "value"sv); + + UNIT_ASSERT_EXCEPTION( + TOptsParseResultTestWrapper(&opts, V({"cmd", "--eq-only", "value"})), + TUsageException); + } + Y_UNIT_TEST(TestStoreResult) { TOptsNoDefault opts; TString data; |