From bc000b5a53d3fc3bb1705680cfe7212464fbe97e Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 14 Sep 2020 14:51:52 +0300 Subject: [PATCH] Add OptionParser::parse_string helper. GitOrigin-RevId: 506b1d9c1b6cfb6029bb87e32a98f08b0d16b2d4 --- td/telegram/cli.cpp | 4 ++-- tdutils/td/utils/OptionParser.h | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index d9c871ba7..f543eb849 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4461,8 +4461,8 @@ void main(int argc, char **argv) { [&](Slice parameter) { api_id = to_integer(parameter); }); options.add_option('\0', "api_id", "Set Telegram API ID", [&](Slice parameter) { api_id = to_integer(parameter); }); - options.add_option('\0', "api-hash", "Set Telegram API hash", [&](Slice parameter) { api_hash = parameter.str(); }); - options.add_option('\0', "api_hash", "Set Telegram API hash", [&](Slice parameter) { api_hash = parameter.str(); }); + options.add_option('\0', "api-hash", "Set Telegram API hash", OptionParser::parse_string(api_hash)); + options.add_option('\0', "api_hash", "Set Telegram API hash", OptionParser::parse_string(api_hash)); options.add_check([&] { if (api_id == 0 || api_hash.empty()) { return Status::Error("You must provide valid api-id and api-hash obtained at https://my.telegram.org"); diff --git a/tdutils/td/utils/OptionParser.h b/tdutils/td/utils/OptionParser.h index af611ec3f..d1ba27f3d 100644 --- a/tdutils/td/utils/OptionParser.h +++ b/tdutils/td/utils/OptionParser.h @@ -39,6 +39,12 @@ class OptionParser { }; } + static std::function parse_string(string &value) { + return [&value](Slice value_str) { + value = value_str.str(); + }; + } + void set_description(string description); void add_checked_option(char short_key, Slice long_key, Slice description, std::function callback);