Skip to content

Commit df60a1e

Browse files
committed
Fix
1 parent 5f47805 commit df60a1e

15 files changed

+65
-58
lines changed

library/cpp/colorizer/colors.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <util/stream/output.h>
44
#include <util/generic/singleton.h>
55

6+
#include <iostream>
7+
68
#if defined(_unix_)
79
#include <unistd.h>
810
#endif
@@ -143,11 +145,11 @@ std::string ToString(NColorizer::EAnsiCode x) {
143145
return std::string(ToStringBufC(x));
144146
}
145147

146-
template<>
147-
void Out<NColorizer::EAnsiCode>(IOutputStream& os, TTypeTraits<NColorizer::EAnsiCode>::TFuncParam x) {
148+
std::ostream& operator<<(std::ostream& os, NColorizer::EAnsiCode x) {
148149
if (AutoColors(os).IsTTY()) {
149150
os << ToStringBufC(x);
150151
}
152+
return os;
151153
}
152154

153155
bool TColors::CalcIsTTY(FILE* file) {
@@ -449,11 +451,11 @@ TColors& NColorizer::StdOut() {
449451
return *Singleton<TStdOutColors>();
450452
}
451453

452-
TColors& NColorizer::AutoColors(IOutputStream& os) {
453-
if (&os == &Cerr) {
454+
TColors& NColorizer::AutoColors(std::ostream& os) {
455+
if (&os == &std::cerr) {
454456
return StdErr();
455457
}
456-
if (&os == &Cout) {
458+
if (&os == &std::cout) {
457459
return StdOut();
458460
}
459461
return *Singleton<TDisabledColors>();

library/cpp/colorizer/colors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ namespace NColorizer {
220220

221221
/// Choose `TColors` depending on output stream. If passed stream is stderr/stdout, return a corresponding
222222
/// singletone. Otherwise, return a disabled singletone (which you can, but should *not* enable).
223-
TColors& AutoColors(IOutputStream& os);
223+
TColors& AutoColors(std::ostream& os);
224224

225225
/// Calculate total length of all ANSI escape codes in the text.
226226
size_t TotalAnsiEscapeCodeLen(std::string_view text);

library/cpp/getopt/small/completer_command.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ namespace NLastGetopt {
9999
if (shell.empty()) {
100100
Cerr << Wrap(80, MakeInfo(command, "--" + name)) << Endl;
101101
} else if (shell == "bash") {
102-
TBashCompletionGenerator(opts).Generate(command, Cout);
102+
TBashCompletionGenerator(opts).Generate(command, std::cout);
103103
} else if (shell == "zsh") {
104-
TZshCompletionGenerator(opts).Generate(command, Cout);
104+
TZshCompletionGenerator(opts).Generate(command, std::cout);
105105
} else {
106106
Cerr << "Unknown shell name " << NUtils::Quote(shell) << Endl;
107107
exit(1);
@@ -140,9 +140,9 @@ namespace NLastGetopt {
140140
NUtils::ToLower(arg);
141141

142142
if (arg == "bash") {
143-
TBashCompletionGenerator(Modes_).Generate(Command_, Cout);
143+
TBashCompletionGenerator(Modes_).Generate(Command_, std::cout);
144144
} else if (arg == "zsh") {
145-
TZshCompletionGenerator(Modes_).Generate(Command_, Cout);
145+
TZshCompletionGenerator(Modes_).Generate(Command_, std::cout);
146146
} else {
147147
Cerr << "Unknown shell name " << NUtils::Quote(arg) << Endl;
148148
parsedOptions.PrintUsage();

library/cpp/getopt/small/completion_generator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace NLastGetopt {
3030
Y_ABORT_UNLESS(opts != nullptr);
3131
}
3232

33-
void TZshCompletionGenerator::Generate(std::string_view command, IOutputStream& stream) {
33+
void TZshCompletionGenerator::Generate(std::string_view command, std::ostream& stream) {
3434
TFormattedOutput out;
3535
NComp::TCompleterManager manager{command};
3636

@@ -370,7 +370,7 @@ namespace NLastGetopt {
370370
line << "' \\";
371371
}
372372

373-
void TBashCompletionGenerator::Generate(std::string_view command, IOutputStream& stream) {
373+
void TBashCompletionGenerator::Generate(std::string_view command, std::ostream& stream) {
374374
TFormattedOutput out;
375375
NComp::TCompleterManager manager{command};
376376

library/cpp/getopt/small/completion_generator.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace NLastGetopt {
1515
virtual ~TCompletionGenerator() = default;
1616

1717
public:
18-
virtual void Generate(std::string_view command, IOutputStream& stream) = 0;
18+
virtual void Generate(std::string_view command, std::ostream& stream) = 0;
1919

2020
protected:
2121
std::variant<const TModChooser*, const TOpts*> Options_;
@@ -26,7 +26,7 @@ namespace NLastGetopt {
2626
using TCompletionGenerator::TCompletionGenerator;
2727

2828
public:
29-
void Generate(std::string_view command, IOutputStream& stream) override;
29+
void Generate(std::string_view command, std::ostream& stream) override;
3030

3131
private:
3232
static void GenerateModesCompletion(TFormattedOutput& out, const TModChooser& chooser, NComp::TCompleterManager& manager);
@@ -40,7 +40,7 @@ namespace NLastGetopt {
4040
using TCompletionGenerator::TCompletionGenerator;
4141

4242
public:
43-
void Generate(std::string_view command, IOutputStream& stream) override;
43+
void Generate(std::string_view command, std::ostream& stream) override;
4444

4545
private:
4646
static void GenerateModesCompletion(TFormattedOutput& out, const TModChooser& chooser, NComp::TCompleterManager& manager, size_t level);

library/cpp/getopt/small/formatted_output.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <util/memory/tempbuf.h>
44
#include <util/generic/algorithm.h>
55

6+
#include <iostream>
7+
68
namespace NLastGetopt {
79

810
TFormattedOutput::IndentGuard::IndentGuard(TFormattedOutput* output)
@@ -23,16 +25,16 @@ namespace NLastGetopt {
2325
return Lines_.emplace_back(IndentLevel_, TStringBuilder()).second;
2426
}
2527

26-
void TFormattedOutput::Print(IOutputStream& out) {
28+
void TFormattedOutput::Print(std::ostream& out) {
2729
for (auto&[indent, line] : Lines_) {
2830
if (indent && !line.empty()) {
2931
TTempBuf buf(indent);
3032
Fill(buf.Data(), buf.Data() + indent, ' ');
31-
out.Write(buf.Data(), indent);
33+
out.write(buf.Data(), indent);
3234
}
3335
out << line;
3436
if (!std::string_view(line).ends_with('\n')) {
35-
out << Endl;
37+
out << std::endl;
3638
}
3739
}
3840
}

library/cpp/getopt/small/formatted_output.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace NLastGetopt {
2222
TStringBuilder& Line();
2323

2424
/// Collect all lines into a stream.
25-
void Print(IOutputStream& out);
25+
void Print(std::ostream& out);
2626

2727
private:
2828
int IndentLevel_ = 0;

library/cpp/getopt/small/last_getopt_opts.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,15 @@ namespace NLastGetopt {
323323
return result.Str();
324324
}
325325

326-
void TOpts::PrintCmdLine(const std::string_view& program, IOutputStream& os, const NColorizer::TColors& colors) const {
326+
void TOpts::PrintCmdLine(const std::string_view& program, std::ostream& os, const NColorizer::TColors& colors) const {
327327
os << colors.BoldColor() << "Usage" << colors.OldColor() << ": ";
328328
if (!CustomUsage.empty()) {
329329
os << CustomUsage;
330330
} else {
331331
os << program << " ";
332332
}
333333
if (!CustomCmdLineDescr.empty()) {
334-
os << CustomCmdLineDescr << Endl;
334+
os << CustomCmdLineDescr << std::endl;
335335
return;
336336
}
337337
os << "[OPTIONS]";
@@ -361,11 +361,11 @@ namespace NLastGetopt {
361361
os << " [" << TrailingArgSpec_.GetTitle(DefaultFreeArgTitle_) << "]...";
362362
}
363363

364-
os << Endl;
364+
os << std::endl;
365365
}
366366

367-
void TOpts::PrintUsage(const std::string_view& program, IOutputStream& osIn, const NColorizer::TColors& colors) const {
368-
TStringStream os;
367+
void TOpts::PrintUsage(const std::string_view& program, std::ostream& osIn, const NColorizer::TColors& colors) const {
368+
std::stringstream os;
369369

370370
if (!Title.empty())
371371
os << Title << "\n\n";
@@ -404,14 +404,14 @@ namespace NLastGetopt {
404404
if (requiredOptionsSection) {
405405
if (requiredOptionsCount == 0)
406406
continue;
407-
os << Endl << colors.BoldColor() << "Required parameters" << colors.OldColor() << ":" << Endl;
407+
os << std::endl << colors.BoldColor() << "Required parameters" << colors.OldColor() << ":" << std::endl;
408408
} else {
409409
if (requiredOptionsCount == Opts_.size())
410410
continue;
411411
if (requiredOptionsCount == 0)
412-
os << Endl << colors.BoldColor() << "Options" << colors.OldColor() << ":" << Endl;
412+
os << std::endl << colors.BoldColor() << "Options" << colors.OldColor() << ":" << std::endl;
413413
else
414-
os << Endl << colors.BoldColor() << "Optional parameters" << colors.OldColor() << ":" << Endl; // optional options would be a tautology
414+
os << std::endl << colors.BoldColor() << "Optional parameters" << colors.OldColor() << ":" << std::endl; // optional options would be a tautology
415415
}
416416

417417
for (size_t i = 0; i < Opts_.size(); i++) {
@@ -423,7 +423,7 @@ namespace NLastGetopt {
423423
continue;
424424

425425
if (leftColumnSizes[i] > leftWidth && !opt->GetHelp().empty()) {
426-
os << SPad << leftColumn[i] << Endl << SPad << leftPadding << ' ';
426+
os << SPad << leftColumn[i] << std::endl << SPad << leftPadding << ' ';
427427
} else {
428428
os << SPad << leftColumn[i] << ' ';
429429
if (leftColumnSizes[i] < leftWidth)
@@ -443,22 +443,22 @@ namespace NLastGetopt {
443443
auto choicesHelp = opt->GetChoicesHelp();
444444
if (!choicesHelp.empty()) {
445445
if (!help.empty()) {
446-
os << Endl << SPad << leftPadding << " ";
446+
os << std::endl << SPad << leftPadding << " ";
447447
}
448448
os << "(values: " << choicesHelp << ")";
449449
}
450450

451451
if (opt->HasDefaultValue()) {
452452
auto quotedDef = QuoteForHelp(opt->GetDefaultValue());
453453
if (helpHasParagraphs) {
454-
os << Endl << Endl << SPad << leftPadding << " ";
454+
os << std::endl << std::endl << SPad << leftPadding << " ";
455455
os << "Default: " << colors.CyanColor() << quotedDef << colors.OldColor() << ".";
456456
} else if (help.ends_with('.')) {
457-
os << Endl << SPad << leftPadding << " ";
457+
os << std::endl << SPad << leftPadding << " ";
458458
os << "Default: " << colors.CyanColor() << quotedDef << colors.OldColor() << ".";
459459
} else if (!help.empty()) {
460460
if (SPad.size() + leftWidth + 1 + lastLineLength + 12 + quotedDef.size() > Wrap_) {
461-
os << Endl << SPad << leftPadding << " ";
461+
os << std::endl << SPad << leftPadding << " ";
462462
} else {
463463
os << " ";
464464
}
@@ -468,30 +468,30 @@ namespace NLastGetopt {
468468
}
469469
}
470470

471-
os << Endl;
471+
os << std::endl;
472472

473473
if (helpHasParagraphs) {
474-
os << Endl;
474+
os << std::endl;
475475
}
476476
}
477477
}
478478

479479
PrintFreeArgsDesc(os, colors);
480480

481481
for (auto& [heading, text] : Sections) {
482-
os << Endl << colors.BoldColor() << heading << colors.OldColor() << ":" << Endl;
482+
os << std::endl << colors.BoldColor() << heading << colors.OldColor() << ":" << std::endl;
483483

484-
os << SPad << Wrap(Wrap_, text, SPad) << Endl;
484+
os << SPad << Wrap(Wrap_, text, SPad) << std::endl;
485485
}
486486

487-
osIn << os.Str();
487+
osIn << os.str();
488488
}
489489

490-
void TOpts::PrintUsage(const std::string_view& program, IOutputStream& os) const {
490+
void TOpts::PrintUsage(const std::string_view& program, std::ostream& os) const {
491491
PrintUsage(program, os, NColorizer::AutoColors(os));
492492
}
493493

494-
void TOpts::PrintFreeArgsDesc(IOutputStream& os, const NColorizer::TColors& colors) const {
494+
void TOpts::PrintFreeArgsDesc(std::ostream& os, const NColorizer::TColors& colors) const {
495495
if (0 == FreeArgsMax_)
496496
return;
497497

@@ -505,7 +505,7 @@ namespace NLastGetopt {
505505
}
506506

507507
leftFreeWidth = Min(leftFreeWidth, size_t(30));
508-
os << Endl << colors.BoldColor() << "Free args" << colors.OldColor() << ":";
508+
os << std::endl << colors.BoldColor() << "Free args" << colors.OldColor() << ":";
509509

510510
os << " min: " << colors.GreenColor() << FreeArgsMin_ << colors.OldColor() << ",";
511511
os << " max: " << colors.GreenColor();
@@ -514,7 +514,7 @@ namespace NLastGetopt {
514514
} else {
515515
os << "unlimited";
516516
}
517-
os << colors.OldColor() << Endl;
517+
os << colors.OldColor() << std::endl;
518518

519519
const size_t limit = FreeArgSpecs_.empty() ? 0 : FreeArgSpecs_.rbegin()->first;
520520
for (size_t i = 0; i <= limit; ++i) {
@@ -524,17 +524,17 @@ namespace NLastGetopt {
524524
auto help = FreeArgSpecs_.at(i).GetHelp();
525525
if (!help.empty()) {
526526
auto title = GetFreeArgTitle(i);
527-
os << SPad << colors.GreenColor() << RightPad(title, leftFreeWidth, ' ') << colors.OldColor()
528-
<< SPad << help << Endl;
527+
os << SPad << colors.GreenColor() << ToString(RightPad(title, leftFreeWidth, ' ')) << colors.OldColor()
528+
<< SPad << help << std::endl;
529529
}
530530
}
531531

532532
if (FreeArgsMax_ == UNLIMITED_ARGS) {
533533
auto title = TrailingArgSpec_.GetTitle(DefaultFreeArgTitle_);
534534
auto help = TrailingArgSpec_.GetHelp();
535535
if (!help.empty()) {
536-
os << SPad << colors.GreenColor() << RightPad(title, leftFreeWidth, ' ') << colors.OldColor()
537-
<< SPad << help << Endl;
536+
os << SPad << colors.GreenColor() << ToString(RightPad(title, leftFreeWidth, ' ')) << colors.OldColor()
537+
<< SPad << help << std::endl;
538538
}
539539
}
540540
}

library/cpp/getopt/small/last_getopt_opts.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
#include "last_getopt_opt.h"
44

5-
#include <map>
65
#include <library/cpp/colorizer/fwd.h>
76

7+
#include <iostream>
8+
#include <map>
89

910
namespace NLastGetopt {
1011
enum EArgPermutation {
@@ -602,15 +603,15 @@ namespace NLastGetopt {
602603
* @param os destination stream
603604
* @param colors colorizer
604605
*/
605-
void PrintUsage(const std::string_view& program, IOutputStream& os, const NColorizer::TColors& colors) const;
606+
void PrintUsage(const std::string_view& program, std::ostream& os, const NColorizer::TColors& colors) const;
606607

607608
/**
608609
* Print usage string
609610
*
610611
* @param program prefix of result (path to the program)
611612
* @param os destination stream
612613
*/
613-
void PrintUsage(const std::string_view& program, IOutputStream& os = Cout) const;
614+
void PrintUsage(const std::string_view& program, std::ostream& os = std::cout) const;
614615

615616
/**
616617
* Get list of options in order of definition.
@@ -639,15 +640,15 @@ namespace NLastGetopt {
639640
* @param os destination stream
640641
* @param colors colorizer
641642
*/
642-
void PrintCmdLine(const std::string_view& program, IOutputStream& os, const NColorizer::TColors& colors) const;
643+
void PrintCmdLine(const std::string_view& program, std::ostream& os, const NColorizer::TColors& colors) const;
643644

644645
/**
645646
* Print usage helper
646647
*
647648
* @param os destination stream
648649
* @param colors colorizer
649650
*/
650-
void PrintFreeArgsDesc(IOutputStream& os, const NColorizer::TColors& colors) const;
651+
void PrintFreeArgsDesc(std::ostream& os, const NColorizer::TColors& colors) const;
651652
};
652653

653654
}

library/cpp/getopt/small/last_getopt_parse_result.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ namespace NLastGetopt {
9999
return Parser_->ProgramName_;
100100
}
101101

102-
void TOptsParseResult::PrintUsage(IOutputStream& os) const {
102+
void TOptsParseResult::PrintUsage(std::ostream& os) const {
103103
Parser_->Opts_->PrintUsage(Parser_->ProgramName_, os);
104104
}
105105

library/cpp/getopt/small/last_getopt_parse_result.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ namespace NLastGetopt {
165165
/**
166166
* Print usage string.
167167
*/
168-
void PrintUsage(IOutputStream& os = Cout) const;
168+
void PrintUsage(std::ostream& os = std::cout) const;
169169

170170
/**
171171
* @return position in [premuted argv] of the first free argument

library/cpp/getopt/small/last_getopt_parser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,11 @@ namespace NLastGetopt {
379379
throw usage; // don't need lineinfo, just the message
380380
}
381381

382-
void TOptsParser::PrintUsage(IOutputStream& os, const NColorizer::TColors& colors) const {
382+
void TOptsParser::PrintUsage(std::ostream& os, const NColorizer::TColors& colors) const {
383383
Opts_->PrintUsage(ProgramName(), os, colors);
384384
}
385385

386-
void TOptsParser::PrintUsage(IOutputStream& os) const {
386+
void TOptsParser::PrintUsage(std::ostream& os) const {
387387
PrintUsage(os, NColorizer::AutoColors(os));
388388
}
389389

0 commit comments

Comments
 (0)