Skip to content

Commit 3a5dcc6

Browse files
authored
Use stdout for --help message (#1937)
Noramlly --help is considered normal output not error output. For example its normally to pipe the output of --help to a pager.
1 parent 2c4e9d8 commit 3a5dcc6

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/support/command-line.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ Options::Options(const std::string& command, const std::string& description)
5151
: debug(false), positional(Arguments::Zero) {
5252
add("--help", "-h", "Show this help message and exit", Arguments::Zero,
5353
[this, command, description](Options* o, const std::string&) {
54-
std::cerr << command;
55-
if (positional != Arguments::Zero) std::cerr << ' ' << positionalName;
56-
std::cerr << "\n\n";
57-
printWrap(std::cerr, 0, description);
58-
std::cerr << "\n\nOptions:\n";
54+
std::cout << command;
55+
if (positional != Arguments::Zero) std::cout << ' ' << positionalName;
56+
std::cout << "\n\n";
57+
printWrap(std::cout, 0, description);
58+
std::cout << "\n\nOptions:\n";
5959
size_t optionWidth = 0;
6060
for (const auto& o : options) {
6161
optionWidth =
@@ -64,12 +64,12 @@ Options::Options(const std::string& command, const std::string& description)
6464
for (const auto& o : options) {
6565
bool long_n_short = o.longName.size() != 0 && o.shortName.size() != 0;
6666
size_t pad = 1 + optionWidth - o.longName.size() - o.shortName.size();
67-
std::cerr << " " << o.longName << (long_n_short ? ',' : ' ')
67+
std::cout << " " << o.longName << (long_n_short ? ',' : ' ')
6868
<< o.shortName << std::string(pad, ' ');
69-
printWrap(std::cerr, optionWidth + 4, o.description);
70-
std::cerr << '\n';
69+
printWrap(std::cout, optionWidth + 4, o.description);
70+
std::cout << '\n';
7171
}
72-
std::cerr << '\n';
72+
std::cout << '\n';
7373
exit(EXIT_SUCCESS);
7474
});
7575
add("--debug", "-d", "Print debug information to stderr", Arguments::Zero,

0 commit comments

Comments
 (0)