Skip to content

Commit

Permalink
Disable CLI update with compiler flag DISABLE_UPDATE (#13919)
Browse files Browse the repository at this point in the history
  • Loading branch information
pnv1 authored Jan 29, 2025
1 parent e6cd127 commit 65b41d0
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 9 deletions.
11 changes: 10 additions & 1 deletion ydb/apps/ydb/commands/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@ LIBRARY(commands)

SRCS(
ydb_cloud_root.cpp
ydb_update.cpp
ydb_version.cpp
)

IF (YDB_CERTIFIED)
CFLAGS(
-DDISABLE_UPDATE
)
ELSE()
SRCS(
ydb_update.cpp
)
ENDIF ()

PEERDIR(
ydb/public/sdk/cpp/src/client/iam
ydb/public/lib/ydb_cli/commands
Expand Down
10 changes: 9 additions & 1 deletion ydb/apps/ydb/commands/ydb_cloud_root.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include "ydb_cloud_root.h"
#include "ydb_update.h"
#include "ydb_version.h"

#include <ydb-cpp-sdk/client/iam/iam.h>
#include <ydb-cpp-sdk/client/types/credentials/oauth2_token_exchange/from_file.h>

#ifndef DISABLE_UPDATE
#include "ydb_update.h"
#include <ydb/public/lib/ydb_cli/common/ydb_updater.h>
#endif

#include <filesystem>

Expand Down Expand Up @@ -56,7 +59,9 @@ void TClientCommandRoot::SetCredentialsGetter(TConfig& config) {
TYCloudClientCommandRoot::TYCloudClientCommandRoot(const TString& name, const TClientSettings& settings)
: TClientCommandRoot(name, settings)
{
#ifndef DISABLE_UPDATE
AddCommand(std::make_unique<TCommandUpdate>());
#endif
AddCommand(std::make_unique<TCommandVersion>());
}

Expand All @@ -79,6 +84,7 @@ void TYCloudClientCommandRoot::Config(TConfig& config) {
}

int TYCloudClientCommandRoot::Run(TConfig& config) {
#ifndef DISABLE_UPDATE
if (config.NeedToCheckForUpdate) {
TYdbUpdater updater;
if (config.ForceVersionCheck) {
Expand All @@ -95,6 +101,8 @@ int TYCloudClientCommandRoot::Run(TConfig& config) {
<< colors.OldColor() << Endl;
}
}
#endif

return TClientCommandRoot::Run(config);
}

Expand Down
13 changes: 12 additions & 1 deletion ydb/apps/ydb/commands/ydb_version.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#include "ydb_version.h"

#include <ydb/public/lib/ydb_cli/common/ydb_updater.h>
#ifndef DISABLE_UPDATE
#include <ydb/public/lib/ydb_cli/common/ydb_updater.h>
#endif

#include <library/cpp/resource/resource.h>
#include <util/string/strip.h>

namespace NYdb::NConsoleClient {

const char* VersionResourceName = "version.txt";

TCommandVersion::TCommandVersion()
: TClientCommand("version", {}, "Print YDB CLI version")
{}
Expand All @@ -20,6 +24,8 @@ void TCommandVersion::Config(TConfig& config) {

config.Opts->AddLongOption("semantic", "Print semantic version only")
.StoreTrue(&Semantic);

#ifndef DISABLE_UPDATE
config.Opts->AddLongOption("check", "Force to check latest version available")
.StoreTrue(&config.ForceVersionCheck);
config.Opts->AddLongOption("disable-checks", "Disable version checks. CLI will not check whether there is a newer version available")
Expand All @@ -33,6 +39,8 @@ void TCommandVersion::Config(TConfig& config) {
config.Opts->MutuallyExclusive("enable-checks", "semantic");
config.Opts->MutuallyExclusive("enable-checks", "check");
config.Opts->MutuallyExclusive("check", "semantic");
#endif

}

void TCommandVersion::Parse(TConfig& config) {
Expand All @@ -44,6 +52,7 @@ void TCommandVersion::Parse(TConfig& config) {
int TCommandVersion::Run(TConfig& config) {
Y_UNUSED(config);

#ifndef DISABLE_UPDATE
if (EnableChecks) {
TYdbUpdater updater;
updater.SetCheckVersion(true);
Expand All @@ -56,6 +65,8 @@ int TCommandVersion::Run(TConfig& config) {
Cout << "Latest version checks disabled" << Endl;
return EXIT_SUCCESS;
}
#endif

if (!Semantic) {
Cout << "YDB CLI ";
}
Expand Down
4 changes: 3 additions & 1 deletion ydb/apps/ydb/commands/ydb_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
namespace NYdb {
namespace NConsoleClient {

extern const char* VersionResourceName;

class TCommandVersion : public TClientCommand {
public:
TCommandVersion();
virtual void Config(TConfig& config) override;
virtual int Run(TConfig& config) override;
virtual int Run(TConfig& config) override;
virtual void Parse(TConfig& config) override;

private:
Expand Down
2 changes: 0 additions & 2 deletions ydb/public/lib/ydb_cli/common/profile_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
namespace NYdb {
namespace NConsoleClient {

extern const char* VersionResourceName;

class IProfile {
public:
virtual ~IProfile() = default;
Expand Down
11 changes: 10 additions & 1 deletion ydb/public/lib/ydb_cli/common/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,19 @@ SRCS(
sys.cpp
tabbed_table.cpp
waiting_bar.cpp
ydb_updater.cpp
yt.cpp
)

IF (YDB_CERTIFIED)
CFLAGS(
-DDISABLE_UPDATE
)
ELSE()
SRCS(
ydb_updater.cpp
)
ENDIF ()

PEERDIR(
contrib/libs/aws-sdk-cpp/aws-cpp-sdk-s3
library/cpp/config
Expand Down
2 changes: 0 additions & 2 deletions ydb/public/lib/ydb_cli/common/ydb_updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
namespace NYdb {
namespace NConsoleClient {

const char* VersionResourceName = "version.txt";

TString GetOsArchitecture() {
#if defined(_win32_)
return "amd64";
Expand Down

0 comments on commit 65b41d0

Please sign in to comment.