diff options
author | miroslav2 <miroslav2@yandex-team.ru> | 2022-02-10 16:50:54 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:54 +0300 |
commit | e13b11cc555cf840f384b0a13c95fda563c7e81b (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library | |
parent | 896ea04259c43c3c46da4b065d4cda47938393b9 (diff) | |
download | ydb-e13b11cc555cf840f384b0a13c95fda563c7e81b.tar.gz |
Restoring authorship annotation for <miroslav2@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library')
-rw-r--r-- | library/cpp/getopt/print.cpp | 14 | ||||
-rw-r--r-- | library/cpp/getopt/small/last_getopt_handlers.h | 2 | ||||
-rw-r--r-- | library/cpp/getopt/small/last_getopt_opts.cpp | 16 | ||||
-rw-r--r-- | library/cpp/getopt/small/modchooser.cpp | 90 | ||||
-rw-r--r-- | library/cpp/getopt/small/modchooser.h | 26 |
5 files changed, 74 insertions, 74 deletions
diff --git a/library/cpp/getopt/print.cpp b/library/cpp/getopt/print.cpp index 04b800863f..8cf1c62e4d 100644 --- a/library/cpp/getopt/print.cpp +++ b/library/cpp/getopt/print.cpp @@ -22,18 +22,18 @@ namespace NLastGetoptPrivate { return ts; } - TString InitShortVersionString() { - TString ts = GetProgramShortVersionData(); - return ts; - } - + TString InitShortVersionString() { + TString ts = GetProgramShortVersionData(); + return ts; + } + TString& VersionString(); - TString& ShortVersionString(); + TString& ShortVersionString(); struct TInit { TInit() { VersionString() = InitVersionString(); - ShortVersionString() = InitShortVersionString(); + ShortVersionString() = InitShortVersionString(); } } Init; diff --git a/library/cpp/getopt/small/last_getopt_handlers.h b/library/cpp/getopt/small/last_getopt_handlers.h index e4216d45f1..d35456ef34 100644 --- a/library/cpp/getopt/small/last_getopt_handlers.h +++ b/library/cpp/getopt/small/last_getopt_handlers.h @@ -20,5 +20,5 @@ namespace NLastGetopt { [[noreturn]] void PrintUsageAndExit(const TOptsParser* parser); [[noreturn]] void PrintVersionAndExit(const TOptsParser* parser); - [[noreturn]] void PrintShortVersionAndExit(const TString& appName); + [[noreturn]] void PrintShortVersionAndExit(const TString& appName); } diff --git a/library/cpp/getopt/small/last_getopt_opts.cpp b/library/cpp/getopt/small/last_getopt_opts.cpp index 2f4022ccff..03c432849f 100644 --- a/library/cpp/getopt/small/last_getopt_opts.cpp +++ b/library/cpp/getopt/small/last_getopt_opts.cpp @@ -15,10 +15,10 @@ namespace NLastGetoptPrivate { static TString data; return data; } - TString& ShortVersionString() { - static TString data; - return data; - } + TString& ShortVersionString() { + static TString data; + return data; + } } namespace NLastGetopt { @@ -29,11 +29,11 @@ namespace NLastGetopt { exit(NLastGetoptPrivate::VersionString().empty()); } - void PrintShortVersionAndExit(const TString& appName) { + void PrintShortVersionAndExit(const TString& appName) { Cout << appName << " version " << (NLastGetoptPrivate::ShortVersionString() ? NLastGetoptPrivate::ShortVersionString() : "not linked with library/cpp/getopt") << Endl; - exit(NLastGetoptPrivate::ShortVersionString().empty()); - } - + exit(NLastGetoptPrivate::ShortVersionString().empty()); + } + // Like TString::Quote(), but does not quote digits-only string static TString QuoteForHelp(const TString& str) { if (str.empty()) diff --git a/library/cpp/getopt/small/modchooser.cpp b/library/cpp/getopt/small/modchooser.cpp index b67ff333da..2fa5cfd070 100644 --- a/library/cpp/getopt/small/modchooser.cpp +++ b/library/cpp/getopt/small/modchooser.cpp @@ -64,7 +64,7 @@ TModChooser::TMode::TMode(const TString& name, TMainClass* main, const TString& : Name(name) , Main(main) , Description(descr) - , Hidden(hidden) + , Hidden(hidden) , NoCompletion(noCompletion) { } @@ -74,7 +74,7 @@ TModChooser::TModChooser() , VersionHandler(nullptr) , ShowSeparated(true) , SvnRevisionOptionDisabled(false) - , PrintShortCommandInUsage(false) + , PrintShortCommandInUsage(false) { } @@ -115,10 +115,10 @@ void TModChooser::AddGroupModeDescription(const TString& description, bool hidde UnsortedModes.push_back(MakeHolder<TMode>(TString(), nullptr, description.data(), hidden, noCompletion)); } -void TModChooser::SetDefaultMode(const TString& mode) { - DefaultMode = mode; -} - +void TModChooser::SetDefaultMode(const TString& mode) { + DefaultMode = mode; +} + void TModChooser::AddAlias(const TString& alias, const TString& mode) { if (!Modes.FindPtr(mode)) { ythrow yexception() << "TMode '" << mode << "' not found in TModChooser."; @@ -148,10 +148,10 @@ void TModChooser::SetSeparationString(const TString& str) { SeparationString = str; } -void TModChooser::SetPrintShortCommandInUsage(bool printShortCommandInUsage = false) { - PrintShortCommandInUsage = printShortCommandInUsage; -} - +void TModChooser::SetPrintShortCommandInUsage(bool printShortCommandInUsage = false) { + PrintShortCommandInUsage = printShortCommandInUsage; +} + void TModChooser::DisableSvnRevisionOption() { SvnRevisionOptionDisabled = true; } @@ -166,18 +166,18 @@ void TModChooser::AddCompletions(TString progName, const TString& name, bool hid int TModChooser::Run(const int argc, const char** argv) const { Y_ENSURE(argc, "Can't run TModChooser with empty list of arguments."); - bool shiftArgs = true; - TString modeName; + bool shiftArgs = true; + TString modeName; if (argc == 1) { - if (DefaultMode.empty()) { - PrintHelp(argv[0]); - return 0; - } else { - modeName = DefaultMode; - shiftArgs = false; - } - } else { - modeName = argv[1]; + if (DefaultMode.empty()) { + PrintHelp(argv[0]); + return 0; + } else { + modeName = DefaultMode; + shiftArgs = false; + } + } else { + modeName = argv[1]; } if (modeName == "-h" || modeName == "--help" || modeName == "-?") { @@ -192,39 +192,39 @@ int TModChooser::Run(const int argc, const char** argv) const { NLastGetopt::PrintVersionAndExit(nullptr); } - auto modeIter = Modes.find(modeName); - if (modeIter == Modes.end() && !DefaultMode.empty()) { - modeIter = Modes.find(DefaultMode); - shiftArgs = false; - } - + auto modeIter = Modes.find(modeName); + if (modeIter == Modes.end() && !DefaultMode.empty()) { + modeIter = Modes.find(DefaultMode); + shiftArgs = false; + } + if (modeIter == Modes.end()) { Cerr << "Unknown mode " << modeName.Quote() << "." << Endl; PrintHelp(argv[0]); return 1; } - if (shiftArgs) { + if (shiftArgs) { TString firstArg; TVector<const char*> nargv(Reserve(argc)); - if (PrintShortCommandInUsage) { + if (PrintShortCommandInUsage) { firstArg = modeIter->second->Name; - } else { + } else { firstArg = argv[0] + TString(" ") + modeIter->second->Name; - } + } nargv.push_back(firstArg.data()); for (int i = 2; i < argc; ++i) { - nargv.push_back(argv[i]); - } + nargv.push_back(argv[i]); + } // According to the standard, "argv[argc] shall be a null pointer" (5.1.2.2.1). // http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1336 nargv.push_back(nullptr); return (*modeIter->second->Main)(nargv.size() - 1, nargv.data()); - } else { + } else { return (*modeIter->second->Main)(argc, argv); } } @@ -291,22 +291,22 @@ void TModChooser::PrintHelp(const TString& progName) const { if (ShowSeparated) { for (const auto& unsortedMode : UnsortedModes) - if (!unsortedMode->Hidden) { - if (unsortedMode->Name.size()) { - Cerr << " " << unsortedMode->FormatFullName(maxModeLen + 4) << unsortedMode->Description << Endl; - } else { - Cerr << SeparationString << Endl; - Cerr << unsortedMode->Description << Endl; - } + if (!unsortedMode->Hidden) { + if (unsortedMode->Name.size()) { + Cerr << " " << unsortedMode->FormatFullName(maxModeLen + 4) << unsortedMode->Description << Endl; + } else { + Cerr << SeparationString << Endl; + Cerr << unsortedMode->Description << Endl; + } } } else { for (const auto& mode : Modes) { if (mode.first != mode.second->Name) continue; // this is an alias - - if (!mode.second->Hidden) { - Cerr << " " << mode.second->FormatFullName(maxModeLen + 4) << mode.second->Description << Endl; - } + + if (!mode.second->Hidden) { + Cerr << " " << mode.second->FormatFullName(maxModeLen + 4) << mode.second->Description << Endl; + } } } diff --git a/library/cpp/getopt/small/modchooser.h b/library/cpp/getopt/small/modchooser.h index 59c3e841c1..0a8de6d50b 100644 --- a/library/cpp/getopt/small/modchooser.h +++ b/library/cpp/getopt/small/modchooser.h @@ -54,12 +54,12 @@ public: void AddMode(const TString& mode, TMainClass* func, const TString& description, bool hidden = false, bool noCompletion = false); void AddMode(const TString& mode, TMainClassV* func, const TString& description, bool hidden = false, bool noCompletion = false); - //! Hidden groups won't be displayed in 'help' block + //! Hidden groups won't be displayed in 'help' block void AddGroupModeDescription(const TString& description, bool hidden = false, bool noCompletion = false); - //! Set default mode (if not specified explicitly) - void SetDefaultMode(const TString& mode); - + //! Set default mode (if not specified explicitly) + void SetDefaultMode(const TString& mode); + void AddAlias(const TString& alias, const TString& mode); //! Set main program description. @@ -77,9 +77,9 @@ public: //! Set separation string void SetSeparationString(const TString& str); - //! Set short command representation in Usage block - void SetPrintShortCommandInUsage(bool printShortCommandInUsage); - + //! Set short command representation in Usage block + void SetPrintShortCommandInUsage(bool printShortCommandInUsage); + void DisableSvnRevisionOption(); void AddCompletions(TString progName, const TString& name = "completion", bool hidden = false, bool noCompletion = false); @@ -106,7 +106,7 @@ public: TString Name; TMainClass* Main; TString Description; - bool Hidden; + bool Hidden; bool NoCompletion; TVector<TString> Aliases; @@ -147,8 +147,8 @@ private: //! Modes TMap<TString, TMode*> Modes; - TString DefaultMode; - + TString DefaultMode; + //! Handler for '--version' parameter TVersionHandlerPtr VersionHandler; @@ -158,9 +158,9 @@ private: //! When set to true, disables --svnrevision option, useful for opensource (git hosted) projects bool SvnRevisionOptionDisabled; - //! When true - will print only 'mode name' in 'Usage' block - bool PrintShortCommandInUsage; - + //! When true - will print only 'mode name' in 'Usage' block + bool PrintShortCommandInUsage; + //! Text string used when displaying each separator TString SeparationString; |