sanjana2505006 commented on code in PR #3372:
URL: https://github.com/apache/kvrocks/pull/3372#discussion_r2811906730
##########
src/cli/main.cc:
##########
@@ -59,15 +60,17 @@ struct NewOpt {
friend auto &operator<<(std::ostream &os, NewOpt) { return os <<
std::string(4, ' ') << std::setw(32); }
} new_opt;
-static void PrintUsage(const char *program) {
- std::cout << program << " implements the Redis protocol based on rocksdb" <<
std::endl
- << "Usage:" << std::endl
- << std::left << new_opt << "-c, --config <filename>" << "set
config file to <filename>, or `-` for stdin"
- << std::endl
- << new_opt << "-v, --version" << "print version information" <<
std::endl
- << new_opt << "-h, --help" << "print this help message" <<
std::endl
- << new_opt << "--<config-key> <config-value>"
- << "overwrite specific config option <config-key> to
<config-value>" << std::endl;
+static void PrintUsage(const char *program, std::ostream &os = std::cout) {
+ os << program << " implements the Redis protocol based on RocksDB" <<
std::endl
Review Comment:
I actually went with the `std::ostream` parameter because I wanted to stick
to the standard way most CLI tools handle output. Usually, when someone asks
for help explicitly (like with `--help`), they expect it on `stdout` so they
can pipe it to `grep` or `less`. But if they just mess up a command, the usage
warning should definitely go to `stderr`.
I also noticed that `--version` uses stdout right now, so this keeps things
consistent.
Let me know if that makes sense! I'm happy to simplify it to just
`std::cerr` if you'd prefer less boilerplate, but I figured this separation was
worth the extra bit of code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]