Add OptionParser::parse_string helper.

GitOrigin-RevId: 506b1d9c1b6cfb6029bb87e32a98f08b0d16b2d4
This commit is contained in:
levlam 2020-09-14 14:51:52 +03:00
parent 91942f29d3
commit bc000b5a53
2 changed files with 8 additions and 2 deletions

View File

@ -4461,8 +4461,8 @@ void main(int argc, char **argv) {
[&](Slice parameter) { api_id = to_integer<int32>(parameter); });
options.add_option('\0', "api_id", "Set Telegram API ID",
[&](Slice parameter) { api_id = to_integer<int32>(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");

View File

@ -39,6 +39,12 @@ class OptionParser {
};
}
static std::function<void(Slice)> 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<Status(Slice)> callback);