diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-12-13 13:23:42 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-12-13 14:31:49 +0300 |
commit | 7e12365effe19ba025ad585c13c2a6b68bfe4703 (patch) | |
tree | eb9fb9d6f86bdecf2ffacea9cd9b5fb75dc31492 | |
parent | fab10ff25473117c056fd8c4ec06e7cbc4783cbd (diff) | |
download | ydb-7e12365effe19ba025ad585c13c2a6b68bfe4703.tar.gz |
Intermediate changes
commit_hash:2a11ff590327dfcbc75eefcb8505784d9eb077d1
-rw-r--r-- | yt/yt/library/program/program.cpp | 18 | ||||
-rw-r--r-- | yt/yt/library/program/program.h | 10 |
2 files changed, 20 insertions, 8 deletions
diff --git a/yt/yt/library/program/program.cpp b/yt/yt/library/program/program.cpp index b4631ada37..ff74660266 100644 --- a/yt/yt/library/program/program.cpp +++ b/yt/yt/library/program/program.cpp @@ -80,6 +80,8 @@ private: TProgram* const Owner_; }; +//////////////////////////////////////////////////////////////////////////////// + TProgram::TProgram() { Opts_.AddHelpOption(); @@ -100,6 +102,8 @@ TProgram::TProgram() ConfigureCoverageOutput(); } +TProgram::~TProgram() = default; + void TProgram::SetCrashOnError() { CrashOnError_ = true; @@ -122,13 +126,12 @@ int TProgram::Run(int argc, const char** argv) { ::srand(time(nullptr)); - auto run = [&] { - Argv0_ = TString(argv[0]); - TOptsParseResult result(this, argc, argv); + Argv0_ = TString(argv[0]); + OptsParseResult_ = std::make_unique<TOptsParseResult>(this, argc, argv); + auto run = [&] { HandleVersionAndBuild(); - - DoRun(result); + DoRun(); }; if (!CrashOnError_) { @@ -212,6 +215,11 @@ void TProgram::PrintVersionAndExit() PrintYTVersionAndExit(); } +const NLastGetopt::TOptsParseResult& TProgram::GetOptsParseResult() const +{ + return *OptsParseResult_; +} + //////////////////////////////////////////////////////////////////////////////// TProgramException::TProgramException(TString what) diff --git a/yt/yt/library/program/program.h b/yt/yt/library/program/program.h index 4bf4dd3015..cd8bf61554 100644 --- a/yt/yt/library/program/program.h +++ b/yt/yt/library/program/program.h @@ -16,6 +16,7 @@ class TProgram { public: TProgram(); + ~TProgram(); TProgram(const TProgram&) = delete; TProgram(TProgram&&) = delete; @@ -50,7 +51,7 @@ protected: bool PrintBuild_ = false; bool UseYson_ = false; - virtual void DoRun(const NLastGetopt::TOptsParseResult& parseResult) = 0; + virtual void DoRun() = 0; virtual void OnError(const TString& message) noexcept; @@ -81,11 +82,14 @@ protected: [[noreturn]] void Exit(E exitCode) noexcept; -private: - bool CrashOnError_ = false; + const NLastGetopt::TOptsParseResult& GetOptsParseResult() const; +private: // Custom handler for option parsing errors. class TOptsParseResult; + + std::unique_ptr<TOptsParseResult> OptsParseResult_; + bool CrashOnError_ = false; }; //////////////////////////////////////////////////////////////////////////////// |