diff options
-rw-r--r-- | cmdline/cmdline_parser.h | 8 | ||||
-rw-r--r-- | cmdline/detail/cmdline_parse_argument_detail.h | 29 |
2 files changed, 16 insertions, 21 deletions
diff --git a/cmdline/cmdline_parser.h b/cmdline/cmdline_parser.h index 5cdf446474..8685da295d 100644 --- a/cmdline/cmdline_parser.h +++ b/cmdline/cmdline_parser.h @@ -739,11 +739,11 @@ void CmdlineParser<TVariantMap, TVariantMapKey>::DumpHelp(VariableIndentationOut std::unordered_map<std::string, std::vector<detail::CmdlineParseArgumentAny*>> args; for (const std::unique_ptr<detail::CmdlineParseArgumentAny>& it : completed_arguments_) { auto cat = it->GetCategory(); - if (cat) { - if (args.find(cat.value()) == args.end()) { - args[cat.value()] = {}; + if (cat.has_value()) { + if (args.find(*cat) == args.end()) { + args[*cat] = {}; } - args.at(cat.value()).push_back(it.get()); + args.at(*cat).push_back(it.get()); } else { uncat.push_back(it.get()); } diff --git a/cmdline/detail/cmdline_parse_argument_detail.h b/cmdline/detail/cmdline_parse_argument_detail.h index 0bde57bbae..de0a588b96 100644 --- a/cmdline/detail/cmdline_parse_argument_detail.h +++ b/cmdline/detail/cmdline_parse_argument_detail.h @@ -149,14 +149,13 @@ struct CmdlineParserArgumentInfo { vios.Stream() << std::endl; for (auto cname : names_) { std::string_view name = cname; - auto& os = vios.Stream(); - // nblank gets captured by print_once, so needs to be declared here. - std::string_view nblank; - std::function<void()> print_once; if (using_blanks_) { - nblank = name.substr(0, name.find("_")); - print_once = [&]() { - os << nblank; + name = name.substr(0, name.find("_")); + } + auto& os = vios.Stream(); + auto print_once = [&]() { + os << name; + if (using_blanks_) { if (has_value_map_) { bool first = true; for (auto [val, unused] : value_map_) { @@ -164,17 +163,13 @@ struct CmdlineParserArgumentInfo { first = false; } os << "}"; - } else if (metavar_) { - os << metavar_.value(); + } else if (metavar_.has_value()) { + os << *metavar_; } else { os << "{" << CmdlineType<T>::DescribeType() << "}"; } - }; - } else { - print_once = [&]() { - os << name; - }; - } + } + }; print_once(); if (appending_values_) { os << " ["; @@ -183,9 +178,9 @@ struct CmdlineParserArgumentInfo { } os << std::endl; } - if (help_) { + if (help_.has_value()) { ScopedIndentation si(&vios); - vios.Stream() << help_.value() << std::endl; + vios.Stream() << *help_ << std::endl; } } |