diff options
author | mvel <mvel@yandex-team.ru> | 2022-02-10 16:45:41 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:41 +0300 |
commit | bd30392c4cc92487950adc375c07adf52da1d592 (patch) | |
tree | e8d1a3f19b7fc890bcef6e4cc5de41f1d88c9ac3 /library/cpp/getopt | |
parent | 5d50718e66d9c037dc587a0211110b7d25a66185 (diff) | |
download | ydb-bd30392c4cc92487950adc375c07adf52da1d592.tar.gz |
Restoring authorship annotation for <mvel@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/getopt')
-rw-r--r-- | library/cpp/getopt/last_getopt_demo/demo.cpp | 10 | ||||
-rw-r--r-- | library/cpp/getopt/small/modchooser.cpp | 24 | ||||
-rw-r--r-- | library/cpp/getopt/small/modchooser.h | 2 | ||||
-rw-r--r-- | library/cpp/getopt/ut/last_getopt_ut.cpp | 78 |
4 files changed, 57 insertions, 57 deletions
diff --git a/library/cpp/getopt/last_getopt_demo/demo.cpp b/library/cpp/getopt/last_getopt_demo/demo.cpp index 79426a9cc9..cbdd7ed458 100644 --- a/library/cpp/getopt/last_getopt_demo/demo.cpp +++ b/library/cpp/getopt/last_getopt_demo/demo.cpp @@ -51,9 +51,9 @@ protected: // Built-in options. opts.AddHelpOption('h'); opts.AddCompletionOption("last_getopt_demo"); - + // Custom options. - + opts.AddLongOption('V', "version") .Help("print version and exit") .IfPresentDisableCompletion() @@ -62,11 +62,11 @@ protected: Cerr << "last_getopt_demo 1.0.0" << Endl; exit(0); }); - + opts.AddLongOption('b', "background") .Help("go to background immediately after startup") .StoreTrue(&Background_); - + opts.AddLongOption("timeout") .RequiredArgument("timeout") .DefaultValue("60000") @@ -110,7 +110,7 @@ protected: .Handler0([this]() { ImplicitMethod_ = "POST"; }); - + opts.AddLongOption("post-file") .RequiredArgument("file") .Help("use POST method and send contents of the specified file in the request body (cannot be used with --post-data)") diff --git a/library/cpp/getopt/small/modchooser.cpp b/library/cpp/getopt/small/modchooser.cpp index 2fa5cfd070..6d11600a46 100644 --- a/library/cpp/getopt/small/modchooser.cpp +++ b/library/cpp/getopt/small/modchooser.cpp @@ -7,9 +7,9 @@ #include <library/cpp/colorizer/colors.h> #include <util/stream/output.h> -#include <util/stream/format.h> +#include <util/stream/format.h> #include <util/generic/yexception.h> -#include <util/generic/ptr.h> +#include <util/generic/ptr.h> #include <util/string/builder.h> #include <util/string/join.h> @@ -99,7 +99,7 @@ void TModChooser::AddMode(const TString& mode, const TMainFunctionPtrV func, con } void TModChooser::AddMode(const TString& mode, TMainClass* func, const TString& description, bool hidden, bool noCompletion) { - if (Modes.FindPtr(mode)) { + if (Modes.FindPtr(mode)) { ythrow yexception() << "TMode '" << mode << "' already exists in TModChooser."; } @@ -184,7 +184,7 @@ int TModChooser::Run(const int argc, const char** argv) const { PrintHelp(argv[0]); return 0; } - if (VersionHandler && (modeName == "-v" || modeName == "--version")) { + if (VersionHandler && (modeName == "-v" || modeName == "--version")) { VersionHandler(); return 0; } @@ -199,7 +199,7 @@ int TModChooser::Run(const int argc, const char** argv) const { } if (modeIter == Modes.end()) { - Cerr << "Unknown mode " << modeName.Quote() << "." << Endl; + Cerr << "Unknown mode " << modeName.Quote() << "." << Endl; PrintHelp(argv[0]); return 1; } @@ -280,9 +280,9 @@ TString TModChooser::TMode::FormatFullName(size_t pad) const { void TModChooser::PrintHelp(const TString& progName) const { Cerr << Description << Endl << Endl; Cerr << NColorizer::StdErr().BoldColor() << "Usage" << NColorizer::StdErr().OldColor() << ": " << progName << " MODE [MODE_OPTIONS]" << Endl; - Cerr << Endl; + Cerr << Endl; Cerr << NColorizer::StdErr().BoldColor() << "Modes" << NColorizer::StdErr().OldColor() << ":" << Endl; - size_t maxModeLen = 0; + size_t maxModeLen = 0; for (const auto& [name, mode] : Modes) { if (name != mode->Name) continue; // this is an alias @@ -309,11 +309,11 @@ void TModChooser::PrintHelp(const TString& progName) const { } } } - - Cerr << Endl; - Cerr << "To get help for specific mode type '" << progName << " MODE " << ModesHelpOption << "'" << Endl; - if (VersionHandler) - Cerr << "To print program version type '" << progName << " --version'" << Endl; + + Cerr << Endl; + Cerr << "To get help for specific mode type '" << progName << " MODE " << ModesHelpOption << "'" << Endl; + if (VersionHandler) + Cerr << "To print program version type '" << progName << " --version'" << Endl; if (!SvnRevisionOptionDisabled) { Cerr << "To print svn revision type --svnrevision" << Endl; } diff --git a/library/cpp/getopt/small/modchooser.h b/library/cpp/getopt/small/modchooser.h index 0a8de6d50b..954d8574ca 100644 --- a/library/cpp/getopt/small/modchooser.h +++ b/library/cpp/getopt/small/modchooser.h @@ -141,7 +141,7 @@ private: //! Help option for modes. TString ModesHelpOption; - //! Wrappers around all modes. + //! Wrappers around all modes. TVector<THolder<TMainClass>> Wrappers; //! Modes diff --git a/library/cpp/getopt/ut/last_getopt_ut.cpp b/library/cpp/getopt/ut/last_getopt_ut.cpp index c99a1d053d..9a06287fec 100644 --- a/library/cpp/getopt/ut/last_getopt_ut.cpp +++ b/library/cpp/getopt/ut/last_getopt_ut.cpp @@ -145,8 +145,8 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { UNIT_ASSERT_VALUES_EQUAL("/etc", r.GetOrElse("to", "trash")); UNIT_ASSERT(r.Has("from")); UNIT_ASSERT(r.Has("to")); - - UNIT_ASSERT_EXCEPTION(r.Get("left"), TException); + + UNIT_ASSERT_EXCEPTION(r.Get("left"), TException); } Y_UNIT_TEST(TestCharOptions) { @@ -160,30 +160,30 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { UNIT_ASSERT(!r.Has('h')); UNIT_ASSERT_VALUES_EQUAL(2u, r.GetFreeArgs().size()); - UNIT_ASSERT_VALUES_EQUAL(2u, r.GetFreeArgCount()); + UNIT_ASSERT_VALUES_EQUAL(2u, r.GetFreeArgCount()); UNIT_ASSERT_VALUES_EQUAL("/etc", r.GetFreeArgs()[0]); UNIT_ASSERT_VALUES_EQUAL("/tmp/etc", r.GetFreeArgs()[1]); } Y_UNIT_TEST(TestFreeArgs) { - TOptsNoDefault opts; - opts.SetFreeArgsNum(1, 3); + TOptsNoDefault opts; + opts.SetFreeArgsNum(1, 3); TOptsParseResultTestWrapper r11(&opts, V({"cp", "/etc"})); TOptsParseResultTestWrapper r12(&opts, V({"cp", "/etc", "/tmp/etc"})); TOptsParseResultTestWrapper r13(&opts, V({"cp", "/etc", "/tmp/etc", "verbose"})); - - UNIT_ASSERT_EXCEPTION( + + UNIT_ASSERT_EXCEPTION( TOptsParseResultTestWrapper(&opts, V({"cp", "/etc", "/tmp/etc", "verbose", "nosymlink"})), yexception); - - UNIT_ASSERT_EXCEPTION( + + UNIT_ASSERT_EXCEPTION( TOptsParseResultTestWrapper(&opts, V({"cp"})), yexception); - - opts.SetFreeArgsNum(2); + + opts.SetFreeArgsNum(2); TOptsParseResultTestWrapper r22(&opts, V({"cp", "/etc", "/var/tmp"})); - } - + } + Y_UNIT_TEST(TestCharOptionsRequiredOptional) { TOptsNoDefault opts; opts.AddCharOption('d', REQUIRED_ARGUMENT); @@ -350,19 +350,19 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { // this test is broken, cause UNIT_ASSERT(false) always throws return; - bool exception = false; - try { - TOpts opts; - opts.AddLongOption('x', "one"); - opts.AddLongOption('x', "two"); - UNIT_ASSERT(false); + bool exception = false; + try { + TOpts opts; + opts.AddLongOption('x', "one"); + opts.AddLongOption('x', "two"); + UNIT_ASSERT(false); } catch (...) { - // we should go here, duplicating options are forbidden - exception = true; - } - UNIT_ASSERT(exception); - } - + // we should go here, duplicating options are forbidden + exception = true; + } + UNIT_ASSERT(exception); + } + Y_UNIT_TEST(TestPositionWhenNoArgs) { TOptsParserTester tester; @@ -527,7 +527,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { // test 'required' opt_d.Required(); - UNIT_ASSERT_EXCEPTION( + UNIT_ASSERT_EXCEPTION( TOptsParseResultTestWrapper(&opts, V({"cmd"})), TUsageException); @@ -563,7 +563,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { opts.AddLongOption("flag2").RequiredArgument().StoreResultT<int>(&uval); opts.AddLongOption("flag3").RequiredArgument().StoreMappedResult(&fval, (double (*)(double))fabs); opts.AddLongOption("flag4").RequiredArgument().StoreMappedResult(&fval, (double (*)(double))sqrt); - UNIT_ASSERT_EXCEPTION( + UNIT_ASSERT_EXCEPTION( TOptsParseResultTestWrapper(&opts, V({"cmd", "--flag3", "-2.0", "--flag1", "-1"})), yexception); UNIT_ASSERT_VALUES_EQUAL(uval, 5u); @@ -575,21 +575,21 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { } Y_UNIT_TEST(TestTitleAndPrintUsage) { - TOpts opts; - const char* prog = "my_program"; + TOpts opts; + const char* prog = "my_program"; TString title = TString("Sample ") + TString(prog).Quote() + " application"; - opts.SetTitle(title); - int argc = 2; + opts.SetTitle(title); + int argc = 2; const char* cmd[] = {prog}; - TOptsParser parser(&opts, argc, cmd); - TStringStream out; - parser.PrintUsage(out); - // find title + TOptsParser parser(&opts, argc, cmd); + TStringStream out; + parser.PrintUsage(out); + // find title UNIT_ASSERT(out.Str().find(title) != TString::npos); - // find usage + // find usage UNIT_ASSERT(out.Str().find(" " + TString(prog) + " ") != TString::npos); - } - + } + Y_UNIT_TEST(TestCustomCmdLineDescr) { TOpts opts; const char* prog = "my_program"; @@ -756,7 +756,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { } { - UNIT_ASSERT_EXCEPTION( + UNIT_ASSERT_EXCEPTION( TOptsParseResultTestWrapper(&opts, V({"cmd", "--true"})), TUsageException); } |