diff options
author | Vasily Gerasimov <UgnineSirdis@gmail.com> | 2022-02-10 16:49:10 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:10 +0300 |
commit | 1eb755fbca92172a6aec2f57371b2b3a19dfab43 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/getopt | |
parent | 6cdc8f140213c595e4ad38bc3d97fcef1146b8c3 (diff) | |
download | ydb-1eb755fbca92172a6aec2f57371b2b3a19dfab43.tar.gz |
Restoring authorship annotation for Vasily Gerasimov <UgnineSirdis@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/getopt')
-rw-r--r-- | library/cpp/getopt/small/last_getopt_opts.cpp | 10 | ||||
-rw-r--r-- | library/cpp/getopt/small/last_getopt_opts.h | 4 | ||||
-rw-r--r-- | library/cpp/getopt/small/last_getopt_parser.cpp | 6 | ||||
-rw-r--r-- | library/cpp/getopt/small/last_getopt_parser.h | 6 | ||||
-rw-r--r-- | library/cpp/getopt/small/modchooser.cpp | 6 | ||||
-rw-r--r-- | library/cpp/getopt/small/ya.make | 4 | ||||
-rw-r--r-- | library/cpp/getopt/ut/last_getopt_ut.cpp | 110 |
7 files changed, 73 insertions, 73 deletions
diff --git a/library/cpp/getopt/small/last_getopt_opts.cpp b/library/cpp/getopt/small/last_getopt_opts.cpp index dfa528b996..03c432849f 100644 --- a/library/cpp/getopt/small/last_getopt_opts.cpp +++ b/library/cpp/getopt/small/last_getopt_opts.cpp @@ -4,7 +4,7 @@ #include "last_getopt_parser.h" #include <library/cpp/colorizer/colors.h> - + #include <util/stream/format.h> #include <util/charset/utf8.h> @@ -62,7 +62,7 @@ namespace NLastGetopt { return opt->ToShortString(); } } - + TOpts::TOpts(const TStringBuf& optstring) : ArgPermutation_(DEFAULT_ARG_PERMUTATION) , AllowSingleDashForLong_(false) @@ -392,14 +392,14 @@ namespace NLastGetopt { if (requiredOptionsCount == 0) continue; os << Endl << colors.BoldColor() << "Required parameters" << colors.OldColor() << ":" << Endl; - } else { + } else { if (requiredOptionsCount == Opts_.size()) continue; if (requiredOptionsCount == 0) os << Endl << colors.BoldColor() << "Options" << colors.OldColor() << ":" << Endl; else os << Endl << colors.BoldColor() << "Optional parameters" << colors.OldColor() << ":" << Endl; // optional options would be a tautology - } + } for (size_t i = 0; i < Opts_.size(); i++) { const TOpt* opt = Opts_[i].Get(); @@ -469,7 +469,7 @@ namespace NLastGetopt { void TOpts::PrintUsage(const TStringBuf& program, IOutputStream& os) const { PrintUsage(program, os, NColorizer::AutoColors(os)); } - + void TOpts::PrintFreeArgsDesc(IOutputStream& os, const NColorizer::TColors& colors) const { if (0 == FreeArgsMax_) return; diff --git a/library/cpp/getopt/small/last_getopt_opts.h b/library/cpp/getopt/small/last_getopt_opts.h index 74a8e67237..825b99c871 100644 --- a/library/cpp/getopt/small/last_getopt_opts.h +++ b/library/cpp/getopt/small/last_getopt_opts.h @@ -3,7 +3,7 @@ #include "last_getopt_opt.h" #include <library/cpp/colorizer/fwd.h> - + #include <util/generic/map.h> namespace NLastGetopt { @@ -594,7 +594,7 @@ namespace NLastGetopt { * @param colors colorizer */ void PrintUsage(const TStringBuf& program, IOutputStream& os, const NColorizer::TColors& colors) const; - + /** * Print usage string * diff --git a/library/cpp/getopt/small/last_getopt_parser.cpp b/library/cpp/getopt/small/last_getopt_parser.cpp index e6c90aaacd..7668b12a03 100644 --- a/library/cpp/getopt/small/last_getopt_parser.cpp +++ b/library/cpp/getopt/small/last_getopt_parser.cpp @@ -1,7 +1,7 @@ #include "last_getopt_parser.h" #include <library/cpp/colorizer/colors.h> - + #include <util/string/escape.h> namespace NLastGetopt { @@ -385,5 +385,5 @@ namespace NLastGetopt { void TOptsParser::PrintUsage(IOutputStream& os) const { PrintUsage(os, NColorizer::AutoColors(os)); } - -} + +} diff --git a/library/cpp/getopt/small/last_getopt_parser.h b/library/cpp/getopt/small/last_getopt_parser.h index 8a38b3ae63..2cf8a6c308 100644 --- a/library/cpp/getopt/small/last_getopt_parser.h +++ b/library/cpp/getopt/small/last_getopt_parser.h @@ -3,7 +3,7 @@ #include "last_getopt_opts.h" #include <library/cpp/colorizer/fwd.h> - + #include <util/generic/hash_set.h> #include <util/generic/list.h> @@ -146,9 +146,9 @@ namespace NLastGetopt { const TString& ProgramName() const { return ProgramName_; } - + void PrintUsage(IOutputStream& os = Cout) const; - + void PrintUsage(IOutputStream& os, const NColorizer::TColors& colors) const; }; } //namespace NLastGetopt diff --git a/library/cpp/getopt/small/modchooser.cpp b/library/cpp/getopt/small/modchooser.cpp index b84fd37c9a..2fa5cfd070 100644 --- a/library/cpp/getopt/small/modchooser.cpp +++ b/library/cpp/getopt/small/modchooser.cpp @@ -5,7 +5,7 @@ #include "modchooser.h" #include <library/cpp/colorizer/colors.h> - + #include <util/stream/output.h> #include <util/stream/format.h> #include <util/generic/yexception.h> @@ -279,9 +279,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 << NColorizer::StdErr().BoldColor() << "Usage" << NColorizer::StdErr().OldColor() << ": " << progName << " MODE [MODE_OPTIONS]" << Endl; Cerr << Endl; - Cerr << NColorizer::StdErr().BoldColor() << "Modes" << NColorizer::StdErr().OldColor() << ":" << Endl; + Cerr << NColorizer::StdErr().BoldColor() << "Modes" << NColorizer::StdErr().OldColor() << ":" << Endl; size_t maxModeLen = 0; for (const auto& [name, mode] : Modes) { if (name != mode->Name) diff --git a/library/cpp/getopt/small/ya.make b/library/cpp/getopt/small/ya.make index e3b8126a58..96de0f04b1 100644 --- a/library/cpp/getopt/small/ya.make +++ b/library/cpp/getopt/small/ya.make @@ -2,9 +2,9 @@ LIBRARY() OWNER(pg) -PEERDIR( +PEERDIR( library/cpp/colorizer -) +) SRCS( completer.cpp diff --git a/library/cpp/getopt/ut/last_getopt_ut.cpp b/library/cpp/getopt/ut/last_getopt_ut.cpp index 6eb0bd5fca..c99a1d053d 100644 --- a/library/cpp/getopt/ut/last_getopt_ut.cpp +++ b/library/cpp/getopt/ut/last_getopt_ut.cpp @@ -4,10 +4,10 @@ #include <library/cpp/testing/unittest/registar.h> #include <util/generic/array_size.h> -#include <util/string/subst.h> -#include <util/string/vector.h> +#include <util/string/subst.h> +#include <util/string/vector.h> #include <util/string/split.h> - + using namespace NLastGetopt; namespace { @@ -605,101 +605,101 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { } Y_UNIT_TEST(TestColorPrint) { - TOpts opts; - const char* prog = "my_program"; - opts.AddLongOption("long_option").Required(); - opts.AddLongOption('o', "other"); - opts.AddCharOption('d').DefaultValue("42"); - opts.AddCharOption('s').DefaultValue("str_default"); - opts.SetFreeArgsNum(123, 456); + TOpts opts; + const char* prog = "my_program"; + opts.AddLongOption("long_option").Required(); + opts.AddLongOption('o', "other"); + opts.AddCharOption('d').DefaultValue("42"); + opts.AddCharOption('s').DefaultValue("str_default"); + opts.SetFreeArgsNum(123, 456); opts.SetFreeArgTitle(0, "first_free_arg", "help"); opts.SetFreeArgTitle(2, "second_free_arg"); opts.AddSection("Section", "Section\n text"); const char* cmd[] = {prog}; - TOptsParser parser(&opts, Y_ARRAY_SIZE(cmd), cmd); - TStringStream out; - NColorizer::TColors colors(true); - parser.PrintUsage(out, colors); - - // find options and green color + TOptsParser parser(&opts, Y_ARRAY_SIZE(cmd), cmd); + TStringStream out; + NColorizer::TColors colors(true); + parser.PrintUsage(out, colors); + + // find options and green color UNIT_ASSERT(out.Str().find(TStringBuilder() << colors.GreenColor() << "--long_option" << colors.OldColor()) != TString::npos); UNIT_ASSERT(out.Str().find(TStringBuilder() << colors.GreenColor() << "--other" << colors.OldColor()) != TString::npos); UNIT_ASSERT(out.Str().find(TStringBuilder() << colors.GreenColor() << "-o" << colors.OldColor()) != TString::npos); UNIT_ASSERT(out.Str().find(TStringBuilder() << colors.GreenColor() << "-d" << colors.OldColor()) != TString::npos); UNIT_ASSERT(out.Str().find(TStringBuilder() << colors.GreenColor() << "-s" << colors.OldColor()) != TString::npos); - - // find default values + + // find default values UNIT_ASSERT(out.Str().find(TStringBuilder() << colors.CyanColor() << "42" << colors.OldColor()) != TString::npos); UNIT_ASSERT(out.Str().find(TStringBuilder() << colors.CyanColor() << "\"str_default\"" << colors.OldColor()) != TString::npos); - - // find free args + + // find free args UNIT_ASSERT(out.Str().find(TStringBuilder() << colors.GreenColor() << "123" << colors.OldColor()) != TString::npos); UNIT_ASSERT(out.Str().find(TStringBuilder() << colors.GreenColor() << "456" << colors.OldColor()) != TString::npos); UNIT_ASSERT(out.Str().find(TStringBuilder() << colors.GreenColor() << "first_free_arg" << colors.OldColor()) != TString::npos); // free args without help not rendered even if they have custom title UNIT_ASSERT(out.Str().find(TStringBuilder() << colors.GreenColor() << "second_free_arg" << colors.OldColor()) == TString::npos); - - // find signatures + + // find signatures UNIT_ASSERT(out.Str().find(TStringBuilder() << colors.BoldColor() << "Usage" << colors.OldColor()) != TString::npos); UNIT_ASSERT(out.Str().find(TStringBuilder() << colors.BoldColor() << "Required parameters" << colors.OldColor()) != TString::npos); UNIT_ASSERT(out.Str().find(TStringBuilder() << colors.BoldColor() << "Optional parameters" << colors.OldColor()) != TString::npos); UNIT_ASSERT(out.Str().find(TStringBuilder() << colors.BoldColor() << "Free args" << colors.OldColor()) != TString::npos); - + // find sections UNIT_ASSERT(out.Str().find(TStringBuilder() << colors.BoldColor() << "Section" << colors.OldColor() << ":") != TString::npos); UNIT_ASSERT(out.Str().find(TStringBuilder() << " Section\n text") != TString::npos); - // print without colors - TStringStream out2; - opts.PrintUsage(prog, out2); + // print without colors + TStringStream out2; + opts.PrintUsage(prog, out2); UNIT_ASSERT(out2.Str().find(colors.GreenColor()) == TString::npos); UNIT_ASSERT(out2.Str().find(colors.CyanColor()) == TString::npos); UNIT_ASSERT(out2.Str().find(colors.BoldColor()) == TString::npos); UNIT_ASSERT(out2.Str().find(colors.OldColor()) == TString::npos); - } - + } + Y_UNIT_TEST(TestPadding) { - const bool withColorsOpt[] = {false, true}; - for (bool withColors : withColorsOpt) { - TOpts opts; - const char* prog = "my_program"; + const bool withColorsOpt[] = {false, true}; + for (bool withColors : withColorsOpt) { + TOpts opts; + const char* prog = "my_program"; opts.AddLongOption("option", "description 1").Required(); // long option opts.AddLongOption('o', "other", "description 2"); // char and long option opts.AddCharOption('d', "description 3").RequiredArgument("DD"); // char option - opts.AddCharOption('s', "description 4\ndescription 5\ndescription 6"); // multiline desc - opts.AddLongOption('l', "very_very_very_loooong_ooooption", "description 7").RequiredArgument("LONG_ARGUMENT"); + opts.AddCharOption('s', "description 4\ndescription 5\ndescription 6"); // multiline desc + opts.AddLongOption('l', "very_very_very_loooong_ooooption", "description 7").RequiredArgument("LONG_ARGUMENT"); const char* cmd[] = {prog}; - TOptsParser parser(&opts, Y_ARRAY_SIZE(cmd), cmd); - - TStringStream out; - NColorizer::TColors colors(withColors); - parser.PrintUsage(out, colors); - + TOptsParser parser(&opts, Y_ARRAY_SIZE(cmd), cmd); + + TStringStream out; + NColorizer::TColors colors(withColors); + parser.PrintUsage(out, colors); + TString printed = out.Str(); - if (withColors) { - // remove not printable characters + if (withColors) { + // remove not printable characters SubstGlobal(printed, TString(colors.BoldColor()), ""); SubstGlobal(printed, TString(colors.GreenColor()), ""); SubstGlobal(printed, TString(colors.CyanColor()), ""); SubstGlobal(printed, TString(colors.OldColor()), ""); - } + } TVector<TString> lines; StringSplitter(printed).Split('\n').SkipEmpty().Collect(&lines); - UNIT_ASSERT(!lines.empty()); + UNIT_ASSERT(!lines.empty()); TVector<size_t> indents; for (const TString& line : lines) { - const size_t indent = line.find("description "); + const size_t indent = line.find("description "); if (indent != TString::npos) - indents.push_back(indent); - } - UNIT_ASSERT_VALUES_EQUAL(indents.size(), 7); - const size_t theOnlyIndent = indents[0]; - for (size_t indent : indents) { - UNIT_ASSERT_VALUES_EQUAL_C(indent, theOnlyIndent, printed); - } - } - } - + indents.push_back(indent); + } + UNIT_ASSERT_VALUES_EQUAL(indents.size(), 7); + const size_t theOnlyIndent = indents[0]; + for (size_t indent : indents) { + UNIT_ASSERT_VALUES_EQUAL_C(indent, theOnlyIndent, printed); + } + } + } + Y_UNIT_TEST(TestAppendTo) { TVector<int> ints; |