diff options
author | Nikolay Perfilov <pnv902@gmail.com> | 2022-06-29 21:46:22 +0300 |
---|---|---|
committer | Nikolay Perfilov <pnv902@gmail.com> | 2022-06-29 21:46:22 +0300 |
commit | db6e58f55cf68d279e79172f0ec3a7e2e0a81609 (patch) | |
tree | fa487821e3df6044e50c47aab5a48c7e10f99a5f | |
parent | bd2ec263a24c74d94ea5f058e03c0579c42c7994 (diff) | |
download | ydb-db6e58f55cf68d279e79172f0ec3a7e2e0a81609.tar.gz |
Fix ydb init command to work without profile, KIKIMR-15218
ref:5f4fd38ac8283de4d2b7fad4118062d8b8a442df
-rw-r--r-- | ydb/public/lib/ydb_cli/commands/ydb_root_common.cpp | 18 | ||||
-rw-r--r-- | ydb/public/lib/ydb_cli/common/command.h | 40 |
2 files changed, 30 insertions, 28 deletions
diff --git a/ydb/public/lib/ydb_cli/commands/ydb_root_common.cpp b/ydb/public/lib/ydb_cli/commands/ydb_root_common.cpp index 2b37da02946..3be1dc27451 100644 --- a/ydb/public/lib/ydb_cli/commands/ydb_root_common.cpp +++ b/ydb/public/lib/ydb_cli/commands/ydb_root_common.cpp @@ -227,8 +227,10 @@ void TClientCommandRootCommon::Parse(TConfig& config) { ParseProfile(); TClientCommandRootBase::Parse(config); - ParseDatabase(config); - ParseCaCerts(config); + if (!config.IsSystemCommand()) { + ParseDatabase(config); + ParseCaCerts(config); + } config.IsVerbose = IsVerbose; } @@ -292,15 +294,11 @@ void TClientCommandRootCommon::ParseDatabase(TConfig& config) { } if (Database.empty()) { - if (!config.IsSystemCommand()) { - throw TMisuseException() - << "Missing required option 'database'."; - } + throw TMisuseException() + << "Missing required option 'database'."; } else if (!Database.StartsWith('/')) { - if (!config.IsSystemCommand()) { - throw TMisuseException() << "Path to a database \"" << Database - << "\" is incorrect. It must be absolute and thus must begin with '/'."; - } + throw TMisuseException() << "Path to a database \"" << Database + << "\" is incorrect. It must be absolute and thus must begin with '/'."; } config.Database = Database; } diff --git a/ydb/public/lib/ydb_cli/common/command.h b/ydb/public/lib/ydb_cli/common/command.h index 41d2683302a..5f3251a8390 100644 --- a/ydb/public/lib/ydb_cli/common/command.h +++ b/ydb/public/lib/ydb_cli/common/command.h @@ -70,6 +70,8 @@ public: int ArgC; char** ArgV; + int InitialArgC; + char** InitialArgV; NLastGetopt::TOpts* Opts; const NLastGetopt::TOptsParseResult* ParseResult; TVector<TString> Tokens; @@ -110,6 +112,8 @@ public: TConfig(int argc, char** argv) : ArgC(argc) , ArgV(argv) + , InitialArgC(argc) + , InitialArgV(argv) , Opts(nullptr) , ParseResult(nullptr) , TabletId(0) @@ -122,36 +126,36 @@ public: }; } - bool IsHelpCommand() { + bool IsHelpCommand() const { TString lastArg = ArgV[ArgC - 1]; return lastArg == "--help" || lastArg == "-h" || lastArg == "-?"; } - bool IsSvnVersionCommand() { + bool IsSvnVersionCommand() const { TString lastArg = ArgV[ArgC - 1]; return lastArg == "--svnrevision" || lastArg == "-V"; } - bool IsVersionCommand() { + bool IsVersionCommand() const { return HasArgs({ "version" }); } - bool IsVersionForceCheckCommand() { + bool IsVersionForceCheckCommand() const { return HasArgs({ "version", "--check" }); } - bool IsSetVersionCheckCommand() { + bool IsSetVersionCheckCommand() const { return HasArgs({ "version", "--enable-checks" }) || HasArgs({ "version", "--disable-checks" }); } - bool IsUpdateCommand() { + bool IsUpdateCommand() const { return HasArgs({ "update" }); } - bool IsInitCommand() { - TString lastArg = ArgV[ArgC - 1]; - if (lastArg == "init" && ArgC > 1) { - TString penultimateArg = ArgV[ArgC - 2]; + bool IsInitCommand() const { + TString lastArg = InitialArgV[InitialArgC - 1]; + if (lastArg == "init" && InitialArgC > 1) { + TString penultimateArg = InitialArgV[InitialArgC - 2]; if (penultimateArg.EndsWith("ydb") || penultimateArg.EndsWith("ydb.exe")) { return true; } @@ -159,7 +163,7 @@ public: return false; } - bool IsProfileCommand() { + bool IsProfileCommand() const { for (int i = 1; i < 3; ++i) { if (ArgC <= i) { return false; @@ -172,22 +176,22 @@ public: return false; } - bool IsLicenseCommand() { + bool IsLicenseCommand() const { TString lastArg = ArgV[ArgC - 1]; return lastArg == "--license"; } - bool IsCreditsCommand() { + bool IsCreditsCommand() const { TString lastArg = ArgV[ArgC - 1]; return lastArg == "--credits"; } - bool IsHelpExCommand() { + bool IsHelpExCommand() const { TString lastArg = ArgV[ArgC - 1]; return lastArg == "--help-ex"; } - bool IsSystemCommand() { + bool IsSystemCommand() const { return IsHelpCommand() || IsSvnVersionCommand() || IsUpdateCommand() || IsVersionCommand() || IsInitCommand() || IsProfileCommand() || IsLicenseCommand() || IsCreditsCommand() || IsHelpExCommand(); @@ -287,11 +291,11 @@ public: return result; } - bool HasArgs(std::vector<TString> args) { + bool HasArgs(const std::vector<TString>& args) const { for (const auto& arg : args) { bool found = false; - for (int i = 0; i < ArgC; ++i) { - if (ArgV[i] == arg) { + for (int i = 0; i < InitialArgC; ++i) { + if (InitialArgV[i] == arg) { found = true; break; } |