Skip to content

Make ydb_root_common use only stderr to avoid command output pollution #1218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions ydb/public/lib/ydb_cli/commands/ydb_root_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ void TClientCommandRootCommon::Parse(TConfig& config) {

namespace {
inline void PrintSettingFromProfile(const TString& setting, std::shared_ptr<IProfile> profile, bool explicitOption) {
Cout << "Using " << setting << " due to configuration in" << (explicitOption ? "" : " active") << " profile \""
Cerr << "Using " << setting << " due to configuration in" << (explicitOption ? "" : " active") << " profile \""
<< profile->GetName() << "\"" << (explicitOption ? " from explicit --profile option" : "") << Endl;
}

Expand Down Expand Up @@ -738,42 +738,42 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) {
config.SecurityToken = ReadFromFile(TokenFile, "token");
config.ChosenAuthMethod = "token";
if (IsVerbose()) {
Cout << "Using token from file provided with explicit option" << Endl;
Cerr << "Using token from file provided with explicit option" << Endl;
config.ConnectionParams["token"].push_back({config.SecurityToken, "file provided with explicit --token-file option"});
}
} else if (config.ParseResult->Has("iam-token-file")) {
config.SecurityToken = ReadFromFile(TokenFile, "token");
config.ChosenAuthMethod = "token";
if (IsVerbose()) {
Cout << "Using IAM token from file provided with explicit option" << Endl;
Cerr << "Using IAM token from file provided with explicit option" << Endl;
config.ConnectionParams["token"].push_back({config.SecurityToken, "file provided with explicit --iam-token-file option"});
}
} else if (YCTokenFile) {
config.YCToken = ReadFromFile(YCTokenFile, "token");
config.ChosenAuthMethod = "yc-token";
if (IsVerbose()) {
Cout << "Using Yandex.Cloud Passport token from file provided with --yc-token-file option" << Endl;
Cerr << "Using Yandex.Cloud Passport token from file provided with --yc-token-file option" << Endl;
config.ConnectionParams["yc-token"].push_back({config.YCToken, "file provided with explicit --yc-token-file option"});
}
} else if (UseMetadataCredentials) {
config.ChosenAuthMethod = "use-metadata-credentials";
config.UseMetadataCredentials = true;
if (IsVerbose()) {
Cout << "Using metadata service due to --use-metadata-credentials option" << Endl;
Cerr << "Using metadata service due to --use-metadata-credentials option" << Endl;
config.ConnectionParams["use-metadata-credentials"].push_back({"true", "explicit --use-metadata-credentials option"});
}
} else if (SaKeyFile) {
config.SaKeyFile = SaKeyFile;
config.ChosenAuthMethod = "sa-key-file";
if (IsVerbose()) {
Cout << "Using service account key file provided with --sa-key-file option" << Endl;
Cerr << "Using service account key file provided with --sa-key-file option" << Endl;
config.ConnectionParams["sa-key-file"].push_back({config.SaKeyFile, "explicit --sa-key-file option"});
}
} else if (UserName || PasswordFile) {
if (UserName) {
config.StaticCredentials.User = UserName;
if (IsVerbose()) {
Cout << "Using user name provided with --user option" << Endl;
Cerr << "Using user name provided with --user option" << Endl;
config.ConnectionParams["user"].push_back({UserName, "explicit --user option"});
}
}
Expand All @@ -783,7 +783,7 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) {
DoNotAskForPassword = true;
}
if (IsVerbose()) {
Cout << "Using user password from file provided with --password-file option" << Endl;
Cerr << "Using user password from file provided with --password-file option" << Endl;
config.ConnectionParams["password"].push_back({config.StaticCredentials.Password, "file provided with explicit --password-file option"});
}
}
Expand All @@ -806,7 +806,7 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) {
if (!envIamToken.empty()) {
if (!IsAuthSet) {
if (IsVerbose()) {
Cout << "Using iam token from IAM_TOKEN env variable" << Endl;
Cerr << "Using iam token from IAM_TOKEN env variable" << Endl;
}
config.ChosenAuthMethod = "token";
config.SecurityToken = envIamToken;
Expand All @@ -821,7 +821,7 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) {
if (!envYcToken.empty()) {
if (!IsAuthSet) {
if (IsVerbose()) {
Cout << "Using Yandex.Cloud Passport token from YC_TOKEN env variable" << Endl;
Cerr << "Using Yandex.Cloud Passport token from YC_TOKEN env variable" << Endl;
}
config.ChosenAuthMethod = "yc-token";
config.YCToken = envYcToken;
Expand All @@ -835,7 +835,7 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) {
if (GetEnv("USE_METADATA_CREDENTIALS") == "1") {
if (!IsAuthSet) {
if (IsVerbose()) {
Cout << "Using metadata service due to USE_METADATA_CREDENTIALS=\"1\" env variable" << Endl;
Cerr << "Using metadata service due to USE_METADATA_CREDENTIALS=\"1\" env variable" << Endl;
}
config.ChosenAuthMethod = "use-metadata-credentials";
config.UseMetadataCredentials = true;
Expand All @@ -850,7 +850,7 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) {
if (!envSaKeyFile.empty()) {
if (!IsAuthSet) {
if (IsVerbose()) {
Cout << "Using service account key file from SA_KEY_FILE env variable" << Endl;
Cerr << "Using service account key file from SA_KEY_FILE env variable" << Endl;
}
config.ChosenAuthMethod = "sa-key-file";
config.SaKeyFile = envSaKeyFile;
Expand All @@ -867,7 +867,7 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) {
if (!envYdbToken.empty()) {
if (!IsAuthSet) {
if (IsVerbose()) {
Cout << "Using OAuth token from YDB_TOKEN env variable" << Endl;
Cerr << "Using OAuth token from YDB_TOKEN env variable" << Endl;
}
config.ChosenAuthMethod = "token";
config.SecurityToken = envYdbToken;
Expand All @@ -885,7 +885,7 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) {
if (!userName.empty()) {
if (!IsAuthSet) {
if (IsVerbose()) {
Cout << "Using user name from YDB_USER env variable" << Endl;
Cerr << "Using user name from YDB_USER env variable" << Endl;
}
hasStaticCredentials = true;
config.StaticCredentials.User = userName;
Expand All @@ -899,7 +899,7 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) {
if (!password.empty()) {
if (!IsAuthSet) {
if (IsVerbose()) {
Cout << "Using user password from YDB_PASSWORD env variable" << Endl;
Cerr << "Using user password from YDB_PASSWORD env variable" << Endl;
}
hasStaticCredentials = true;
config.StaticCredentials.Password = password;
Expand Down Expand Up @@ -930,7 +930,7 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) {
if (ReadFromFileIfExists(tokenFile, "default token", fileContent)) {
if (!IsAuthSet) {
if (IsVerbose()) {
Cout << "Using auth token from default token file " << defaultTokenFile << Endl;
Cerr << "Using auth token from default token file " << defaultTokenFile << Endl;
}
config.ChosenAuthMethod = "token";
config.SecurityToken = fileContent;
Expand All @@ -940,7 +940,7 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) {
}
} else {
if (!IsAuthSet && IsVerbose()) {
Cout << "No authentication methods were found. Going without authentication" << Endl;
Cerr << "No authentication methods were found. Going without authentication" << Endl;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions ydb/public/lib/ydb_cli/common/progress_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void TProgressBar::AddProgress(size_t value) {

TProgressBar::~TProgressBar() {
if (!Finished) {
Cout << Endl;
Cerr << Endl;
}
}

Expand Down Expand Up @@ -62,12 +62,12 @@ void TProgressBar::Render()
output += TString("█") * filledBarLen;
output += TString("░") * (barLen - filledBarLen);
output += outputEnd;
Cout << output;
Cerr << output;
if (CurProgress == Capacity) {
Cout << "\n";
Cerr << "\n";
Finished = true;
}
Cout.Flush();
Cerr.Flush();
}

} // namespace NConsoleClient
Expand Down
2 changes: 1 addition & 1 deletion ydb/public/lib/ydb_cli/import/import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ TStatus TImportFileClient::Import(const TVector<TString>& filePaths, const TStri
auto finish = TInstant::Now();
auto duration = finish - start;
progressBar.SetProcess(100);
Cout << "Elapsed: " << duration.SecondsFloat() << " sec\n";
Cerr << "Elapsed: " << duration.SecondsFloat() << " sec\n";

return MakeStatus(EStatus::SUCCESS);
}
Expand Down