cxxopts
cxxopts copied to clipboard
arguments() contains empty keys when existing short-only options
When use a short-only options name, ParseResult::arguments.key()
will be empty string, because only long_name will be insert into m_sequential in parse_option
:
// line 2164~2178
inline
void
OptionParser::parse_option
(
const std::shared_ptr<OptionDetails>& value,
const std::string& /*name*/,
const std::string& arg
)
{
auto hash = value->hash();
auto& result = m_parsed[hash];
result.parse(value, arg);
m_sequential.emplace_back(value->long_name(), arg); // empty key could be insert into m_sequential when option is short-only name.
}
Also, arguments_string()
will output parse results with no name like (where I set short-only option n=16
and m=8
):
= 16
= 8
help = false (default)
long = false (default)
Possible solution:
Add essential_name()
to OptionsDetails
, which return long name, or short name when long name is empty. And use these as key in m_sequential
and m_defaults
Maybe I will create a PR to solve these.