diff options
| author | Nikolay Perfilov <[email protected]> | 2025-07-02 17:50:07 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-07-02 17:50:07 +0300 |
| commit | fbf2fa8792eadfc0ef619e6cd6255fe30bd07bb6 (patch) | |
| tree | 284f0c059d42d47dcd9aa7837618c8a8220e7ac4 | |
| parent | 7eac6de1a2c00baab89eec1bc59780b865e2dead (diff) | |
Improve new ydb cli version message (#20516)
| -rw-r--r-- | ydb/apps/ydb/commands/ydb_root.cpp | 14 | ||||
| -rw-r--r-- | ydb/public/lib/ydb_cli/common/command.cpp | 1 | ||||
| -rw-r--r-- | ydb/public/lib/ydb_cli/common/ydb_updater.cpp | 60 | ||||
| -rw-r--r-- | ydb/public/lib/ydb_cli/common/ydb_updater.h | 2 |
4 files changed, 34 insertions, 43 deletions
diff --git a/ydb/apps/ydb/commands/ydb_root.cpp b/ydb/apps/ydb/commands/ydb_root.cpp index 7b578176a98..ddc27a8711d 100644 --- a/ydb/apps/ydb/commands/ydb_root.cpp +++ b/ydb/apps/ydb/commands/ydb_root.cpp @@ -87,19 +87,7 @@ void TYdbClientCommandRoot::Config(TConfig& config) { int TYdbClientCommandRoot::Run(TConfig& config) { if (config.StorageUrl.has_value() && config.NeedToCheckForUpdate) { TYdbUpdater updater(config.StorageUrl.value()); - if (config.ForceVersionCheck) { - Cout << "Force checking if there is a newer version..." << Endl; - } - if (updater.CheckIfUpdateNeeded(config.ForceVersionCheck)) { - NColorizer::TColors colors = NColorizer::AutoColors(Cerr); - Cerr << colors.Green() << "(!) New version of YDB CLI is available. Run 'ydb update' command for update. " - << "You can also disable further version checks with 'ydb version --disable-checks' command" - << colors.OldColor() << Endl; - } else if (config.ForceVersionCheck) { - NColorizer::TColors colors = NColorizer::AutoColors(Cerr); - Cout << colors.GreenColor() << "Current version is up to date" - << colors.OldColor() << Endl; - } + updater.PrintUpdateMessageIfNeeded(config.ForceVersionCheck); } return TClientCommandRoot::Run(config); diff --git a/ydb/public/lib/ydb_cli/common/command.cpp b/ydb/public/lib/ydb_cli/common/command.cpp index 38c210da935..2fa42adc6f5 100644 --- a/ydb/public/lib/ydb_cli/common/command.cpp +++ b/ydb/public/lib/ydb_cli/common/command.cpp @@ -14,7 +14,6 @@ using namespace NUtils; namespace { void PrintUsageAndThrowHelpPrinted(const NLastGetopt::TOptsParser* parser) { - Cerr << "PrintUsageAndThrowHelpPrinted" << Endl; parser->PrintUsage(); throw TNeedToExitWithCode(EXIT_SUCCESS); } diff --git a/ydb/public/lib/ydb_cli/common/ydb_updater.cpp b/ydb/public/lib/ydb_cli/common/ydb_updater.cpp index 39d558b7013..ff5aa3130d2 100644 --- a/ydb/public/lib/ydb_cli/common/ydb_updater.cpp +++ b/ydb/public/lib/ydb_cli/common/ydb_updater.cpp @@ -11,6 +11,7 @@ #include <util/system/env.h> #include <util/system/execpath.h> #include <util/system/shellcommand.h> +#include <library/cpp/colorizer/output.h> #ifndef _win32_ #include <sys/utsname.h> @@ -65,34 +66,14 @@ TYdbUpdater::~TYdbUpdater() { } } -bool TYdbUpdater::CheckIfUpdateNeeded(bool forceRequest) { - if (!forceRequest && !IsCheckEnabled()) { - return false; - } - if (!forceRequest && Config.Has("outdated") && Config["outdated"].GetBoolean()) { - return true; - } - if (!forceRequest && !IsTimeToCheckForUpdate()) { - return false; - } - - SetConfigValue("last_check", TInstant::Now().Seconds()); - - if (GetLatestVersion()) { - bool isOutdated = MyVersion != LatestVersion; - SetConfigValue("outdated", isOutdated); - return isOutdated; - } - return false; -} - int TYdbUpdater::Update(bool forceUpdate) { - if (!GetLatestVersion()) { - return EXIT_FAILURE; - } - if (!CheckIfUpdateNeeded(/*forceRequest*/ true) && !forceUpdate) { - Cerr << "Current version: \"" << MyVersion << "\". Latest version Available: \"" << LatestVersion - << "\". No need to update. Use '--force' option to update anyway." << Endl; + if (GetLatestVersion()) { + if (MyVersion == LatestVersion && !forceUpdate) { + Cerr << "Current version: \"" << MyVersion << "\". Latest version available: \"" << LatestVersion + << "\". No need to update. Use '--force' option to update anyway." << Endl; + return EXIT_FAILURE; + } + } else { return EXIT_FAILURE; } @@ -127,6 +108,7 @@ int TYdbUpdater::Update(bool forceUpdate) { checkCmd.Run().Wait(); if (checkCmd.GetExitCode() != 0) { Cerr << "Failed to check downloaded binary. " << checkCmd.GetError() << Endl; + tmpPathToBinary.DeleteIfExists(); return EXIT_FAILURE; } Cout << checkCmd.GetOutput(); @@ -145,7 +127,6 @@ int TYdbUpdater::Update(bool forceUpdate) { tmpPathToBinary.RenameTo(fsPathToBinary); Cout << "New binary renamed to " << fsPathToBinary.GetPath() << Endl; - SetConfigValue("outdated", false); return EXIT_SUCCESS; } @@ -223,11 +204,34 @@ bool TYdbUpdater::GetLatestVersion() { if (curlCmd.GetExitCode() == 0) { LatestVersion = StripString(curlCmd.GetOutput()); + SetConfigValue("last_check", TInstant::Now().Seconds()); return true; } Cerr << "(!) Couldn't get latest version from url \"" << versionUrl << "\". " << curlCmd.GetError() << Endl; return false; } +void TYdbUpdater::PrintUpdateMessageIfNeeded(bool forceVersionCheck) { + if (forceVersionCheck) { + Cerr << "Force checking if there is a newer version..." << Endl; + } else if (!IsCheckEnabled() || !IsTimeToCheckForUpdate()) { + return; + } + if (!GetLatestVersion()) { + return; + } + if (MyVersion != LatestVersion) { + NColorizer::TColors colors = NColorizer::AutoColors(Cerr); + Cerr << colors.Green() << "(!) New version of YDB CLI is available. Current version: \"" << MyVersion + << "\", Latest recommended version available: \"" << LatestVersion << "\". Run 'ydb update' command for update. " + << "You can also disable further version checks with 'ydb version --disable-checks' command." + << colors.OldColor() << Endl; + } else if (forceVersionCheck) { + NColorizer::TColors colors = NColorizer::AutoColors(Cerr); + Cerr << colors.GreenColor() << "Current version is up to date" + << colors.OldColor() << Endl; + } +} + } } diff --git a/ydb/public/lib/ydb_cli/common/ydb_updater.h b/ydb/public/lib/ydb_cli/common/ydb_updater.h index b20bf322799..1d4f7d090b0 100644 --- a/ydb/public/lib/ydb_cli/common/ydb_updater.h +++ b/ydb/public/lib/ydb_cli/common/ydb_updater.h @@ -11,9 +11,9 @@ public: TYdbUpdater(std::string storageUrl); ~TYdbUpdater(); - bool CheckIfUpdateNeeded(bool forceRequest = false); int Update(bool forceUpdate); void SetCheckVersion(bool value); + void PrintUpdateMessageIfNeeded(bool forceVersionCheck); private: void LoadConfig(); |
