diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index a453f0fdd..ca8886af4 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4335,7 +4335,7 @@ void main(int argc, char **argv) { use_test_dc = true; return Status::OK(); }); - options.add_option('v', "verbosity", "Verbosity level", [&](Slice level) { + options.add_option('v', "verbosity", "Set verbosity level", [&](Slice level) { int new_verbosity = 1; while (begins_with(level, "v")) { new_verbosity++; @@ -4347,7 +4347,7 @@ void main(int argc, char **argv) { new_verbosity_level = VERBOSITY_NAME(FATAL) + new_verbosity; return Status::OK(); }); - options.add_option('l', "log", "Log file", [&](Slice file_name) { + options.add_option('l', "log", "Log to file", [&](Slice file_name) { if (file_log.init(file_name.str()).is_ok() && file_log.init(file_name.str()).is_ok() && file_log.init(file_name.str(), 1000 << 20).is_ok()) { log_interface = &ts_log; @@ -4362,19 +4362,19 @@ void main(int argc, char **argv) { disable_network = true; return Status::OK(); }); - options.add_option('\0', "api-id", "Telegram API ID", [&](Slice parameter) { + options.add_option('\0', "api-id", "Set Telegram API ID", [&](Slice parameter) { api_id = to_integer(parameter); return Status::OK(); }); - options.add_option('\0', "api_id", "Telegram API ID", [&](Slice parameter) { + options.add_option('\0', "api_id", "Set Telegram API ID", [&](Slice parameter) { api_id = to_integer(parameter); return Status::OK(); }); - options.add_option('\0', "api-hash", "Telegram API hash", [&](Slice parameter) { + options.add_option('\0', "api-hash", "Set Telegram API hash", [&](Slice parameter) { api_hash = parameter.str(); return Status::OK(); }); - options.add_option('\0', "api_hash", "Telegram API hash", [&](Slice parameter) { + options.add_option('\0', "api_hash", "Set Telegram API hash", [&](Slice parameter) { api_hash = parameter.str(); return Status::OK(); }); diff --git a/tdutils/td/utils/OptionParser.cpp b/tdutils/td/utils/OptionParser.cpp index 3f0a1bbe1..034dc993c 100644 --- a/tdutils/td/utils/OptionParser.cpp +++ b/tdutils/td/utils/OptionParser.cpp @@ -135,22 +135,46 @@ Result> OptionParser::run(int argc, char *argv[]) { } StringBuilder &operator<<(StringBuilder &sb, const OptionParser &o) { - sb << o.description_ << "\n"; + if (!o.description_.empty()) { + sb << o.description_ << ". "; + } + sb << "Options:\n"; + + size_t max_length = 0; for (auto &opt : o.options_) { bool has_short_key = opt.short_key != '\0'; + bool has_long_key = !opt.long_key.empty(); + size_t length = (has_short_key ? 2 : 0) + (has_long_key ? 2 + opt.long_key.size() + 2 * has_short_key : 0); + if (opt.type != OptionParser::Option::Type::NoArg) { + length += 5; + } + if (length > max_length) { + max_length = length; + } + } + max_length++; + + for (auto &opt : o.options_) { + bool has_short_key = opt.short_key != '\0'; + sb << " "; + size_t length = max_length; if (has_short_key) { - sb << "-" << opt.short_key; + sb << '-' << opt.short_key; + length -= 2; } if (!opt.long_key.empty()) { if (has_short_key) { - sb << '|'; + sb << ", "; + length -= 2; } sb << "--" << opt.long_key; + length -= 2 + opt.long_key.size(); } if (opt.type != OptionParser::Option::Type::NoArg) { sb << ""; + length -= 5; } - sb << " " << opt.description; + sb << string(length, ' ') << opt.description; sb << '\n'; } return sb;