Skip to content

Commit 0761c67

Browse files
authored
Make ydb_root_common use only stderr to avoid command output pollution (#1218)
* make ydb_root_common use only stderr to avoid command output pollution
1 parent acefc40 commit 0761c67

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

ydb/public/lib/ydb_cli/commands/ydb_root_common.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ void TClientCommandRootCommon::Parse(TConfig& config) {
259259

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

@@ -738,42 +738,42 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) {
738738
config.SecurityToken = ReadFromFile(TokenFile, "token");
739739
config.ChosenAuthMethod = "token";
740740
if (IsVerbose()) {
741-
Cout << "Using token from file provided with explicit option" << Endl;
741+
Cerr << "Using token from file provided with explicit option" << Endl;
742742
config.ConnectionParams["token"].push_back({config.SecurityToken, "file provided with explicit --token-file option"});
743743
}
744744
} else if (config.ParseResult->Has("iam-token-file")) {
745745
config.SecurityToken = ReadFromFile(TokenFile, "token");
746746
config.ChosenAuthMethod = "token";
747747
if (IsVerbose()) {
748-
Cout << "Using IAM token from file provided with explicit option" << Endl;
748+
Cerr << "Using IAM token from file provided with explicit option" << Endl;
749749
config.ConnectionParams["token"].push_back({config.SecurityToken, "file provided with explicit --iam-token-file option"});
750750
}
751751
} else if (YCTokenFile) {
752752
config.YCToken = ReadFromFile(YCTokenFile, "token");
753753
config.ChosenAuthMethod = "yc-token";
754754
if (IsVerbose()) {
755-
Cout << "Using Yandex.Cloud Passport token from file provided with --yc-token-file option" << Endl;
755+
Cerr << "Using Yandex.Cloud Passport token from file provided with --yc-token-file option" << Endl;
756756
config.ConnectionParams["yc-token"].push_back({config.YCToken, "file provided with explicit --yc-token-file option"});
757757
}
758758
} else if (UseMetadataCredentials) {
759759
config.ChosenAuthMethod = "use-metadata-credentials";
760760
config.UseMetadataCredentials = true;
761761
if (IsVerbose()) {
762-
Cout << "Using metadata service due to --use-metadata-credentials option" << Endl;
762+
Cerr << "Using metadata service due to --use-metadata-credentials option" << Endl;
763763
config.ConnectionParams["use-metadata-credentials"].push_back({"true", "explicit --use-metadata-credentials option"});
764764
}
765765
} else if (SaKeyFile) {
766766
config.SaKeyFile = SaKeyFile;
767767
config.ChosenAuthMethod = "sa-key-file";
768768
if (IsVerbose()) {
769-
Cout << "Using service account key file provided with --sa-key-file option" << Endl;
769+
Cerr << "Using service account key file provided with --sa-key-file option" << Endl;
770770
config.ConnectionParams["sa-key-file"].push_back({config.SaKeyFile, "explicit --sa-key-file option"});
771771
}
772772
} else if (UserName || PasswordFile) {
773773
if (UserName) {
774774
config.StaticCredentials.User = UserName;
775775
if (IsVerbose()) {
776-
Cout << "Using user name provided with --user option" << Endl;
776+
Cerr << "Using user name provided with --user option" << Endl;
777777
config.ConnectionParams["user"].push_back({UserName, "explicit --user option"});
778778
}
779779
}
@@ -783,7 +783,7 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) {
783783
DoNotAskForPassword = true;
784784
}
785785
if (IsVerbose()) {
786-
Cout << "Using user password from file provided with --password-file option" << Endl;
786+
Cerr << "Using user password from file provided with --password-file option" << Endl;
787787
config.ConnectionParams["password"].push_back({config.StaticCredentials.Password, "file provided with explicit --password-file option"});
788788
}
789789
}
@@ -806,7 +806,7 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) {
806806
if (!envIamToken.empty()) {
807807
if (!IsAuthSet) {
808808
if (IsVerbose()) {
809-
Cout << "Using iam token from IAM_TOKEN env variable" << Endl;
809+
Cerr << "Using iam token from IAM_TOKEN env variable" << Endl;
810810
}
811811
config.ChosenAuthMethod = "token";
812812
config.SecurityToken = envIamToken;
@@ -821,7 +821,7 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) {
821821
if (!envYcToken.empty()) {
822822
if (!IsAuthSet) {
823823
if (IsVerbose()) {
824-
Cout << "Using Yandex.Cloud Passport token from YC_TOKEN env variable" << Endl;
824+
Cerr << "Using Yandex.Cloud Passport token from YC_TOKEN env variable" << Endl;
825825
}
826826
config.ChosenAuthMethod = "yc-token";
827827
config.YCToken = envYcToken;
@@ -835,7 +835,7 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) {
835835
if (GetEnv("USE_METADATA_CREDENTIALS") == "1") {
836836
if (!IsAuthSet) {
837837
if (IsVerbose()) {
838-
Cout << "Using metadata service due to USE_METADATA_CREDENTIALS=\"1\" env variable" << Endl;
838+
Cerr << "Using metadata service due to USE_METADATA_CREDENTIALS=\"1\" env variable" << Endl;
839839
}
840840
config.ChosenAuthMethod = "use-metadata-credentials";
841841
config.UseMetadataCredentials = true;
@@ -850,7 +850,7 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) {
850850
if (!envSaKeyFile.empty()) {
851851
if (!IsAuthSet) {
852852
if (IsVerbose()) {
853-
Cout << "Using service account key file from SA_KEY_FILE env variable" << Endl;
853+
Cerr << "Using service account key file from SA_KEY_FILE env variable" << Endl;
854854
}
855855
config.ChosenAuthMethod = "sa-key-file";
856856
config.SaKeyFile = envSaKeyFile;
@@ -867,7 +867,7 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) {
867867
if (!envYdbToken.empty()) {
868868
if (!IsAuthSet) {
869869
if (IsVerbose()) {
870-
Cout << "Using OAuth token from YDB_TOKEN env variable" << Endl;
870+
Cerr << "Using OAuth token from YDB_TOKEN env variable" << Endl;
871871
}
872872
config.ChosenAuthMethod = "token";
873873
config.SecurityToken = envYdbToken;
@@ -885,7 +885,7 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) {
885885
if (!userName.empty()) {
886886
if (!IsAuthSet) {
887887
if (IsVerbose()) {
888-
Cout << "Using user name from YDB_USER env variable" << Endl;
888+
Cerr << "Using user name from YDB_USER env variable" << Endl;
889889
}
890890
hasStaticCredentials = true;
891891
config.StaticCredentials.User = userName;
@@ -899,7 +899,7 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) {
899899
if (!password.empty()) {
900900
if (!IsAuthSet) {
901901
if (IsVerbose()) {
902-
Cout << "Using user password from YDB_PASSWORD env variable" << Endl;
902+
Cerr << "Using user password from YDB_PASSWORD env variable" << Endl;
903903
}
904904
hasStaticCredentials = true;
905905
config.StaticCredentials.Password = password;
@@ -930,7 +930,7 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) {
930930
if (ReadFromFileIfExists(tokenFile, "default token", fileContent)) {
931931
if (!IsAuthSet) {
932932
if (IsVerbose()) {
933-
Cout << "Using auth token from default token file " << defaultTokenFile << Endl;
933+
Cerr << "Using auth token from default token file " << defaultTokenFile << Endl;
934934
}
935935
config.ChosenAuthMethod = "token";
936936
config.SecurityToken = fileContent;
@@ -940,7 +940,7 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) {
940940
}
941941
} else {
942942
if (!IsAuthSet && IsVerbose()) {
943-
Cout << "No authentication methods were found. Going without authentication" << Endl;
943+
Cerr << "No authentication methods were found. Going without authentication" << Endl;
944944
}
945945
}
946946
}

ydb/public/lib/ydb_cli/common/progress_bar.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void TProgressBar::AddProgress(size_t value) {
2626

2727
TProgressBar::~TProgressBar() {
2828
if (!Finished) {
29-
Cout << Endl;
29+
Cerr << Endl;
3030
}
3131
}
3232

@@ -62,12 +62,12 @@ void TProgressBar::Render()
6262
output += TString("") * filledBarLen;
6363
output += TString("") * (barLen - filledBarLen);
6464
output += outputEnd;
65-
Cout << output;
65+
Cerr << output;
6666
if (CurProgress == Capacity) {
67-
Cout << "\n";
67+
Cerr << "\n";
6868
Finished = true;
6969
}
70-
Cout.Flush();
70+
Cerr.Flush();
7171
}
7272

7373
} // namespace NConsoleClient

ydb/public/lib/ydb_cli/import/import.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ TStatus TImportFileClient::Import(const TVector<TString>& filePaths, const TStri
349349
auto finish = TInstant::Now();
350350
auto duration = finish - start;
351351
progressBar.SetProcess(100);
352-
Cout << "Elapsed: " << duration.SecondsFloat() << " sec\n";
352+
Cerr << "Elapsed: " << duration.SecondsFloat() << " sec\n";
353353

354354
return MakeStatus(EStatus::SUCCESS);
355355
}

0 commit comments

Comments
 (0)