Allow positional arguments to show in help
Fixes #72. This adds an option for positional arguments to be shown in the help output.
This commit is contained in:
parent
4ebfa25915
commit
24450d183a
@ -1118,6 +1118,7 @@ namespace cxxopts
|
||||
: m_program(std::move(program))
|
||||
, m_help_string(toLocalString(std::move(help_string)))
|
||||
, m_positional_help("positional parameters")
|
||||
, m_show_positional(false)
|
||||
, m_next_positional(m_positional.end())
|
||||
{
|
||||
}
|
||||
@ -1129,6 +1130,13 @@ namespace cxxopts
|
||||
return *this;
|
||||
}
|
||||
|
||||
Options&
|
||||
show_positional_help()
|
||||
{
|
||||
m_show_positional = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ParseResult
|
||||
parse(int& argc, char**& argv);
|
||||
|
||||
@ -1187,6 +1195,7 @@ namespace cxxopts
|
||||
std::string m_program;
|
||||
String m_help_string;
|
||||
std::string m_positional_help;
|
||||
bool m_show_positional;
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<OptionDetails>> m_options;
|
||||
std::vector<std::string> m_positional;
|
||||
@ -1788,7 +1797,9 @@ Options::help_one_group(const std::string& g) const
|
||||
|
||||
for (const auto& o : group->second.options)
|
||||
{
|
||||
if (o.is_container && m_positional_set.find(o.l) != m_positional_set.end())
|
||||
if (o.is_container &&
|
||||
m_positional_set.find(o.l) != m_positional_set.end() &&
|
||||
!m_show_positional)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -1806,7 +1817,9 @@ Options::help_one_group(const std::string& g) const
|
||||
auto fiter = format.begin();
|
||||
for (const auto& o : group->second.options)
|
||||
{
|
||||
if (o.is_container && m_positional_set.find(o.l) != m_positional_set.end())
|
||||
if (o.is_container &&
|
||||
m_positional_set.find(o.l) != m_positional_set.end() &&
|
||||
!m_show_positional)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -31,7 +31,9 @@ int main(int argc, char* argv[])
|
||||
try
|
||||
{
|
||||
cxxopts::Options options(argv[0], " - example command line options");
|
||||
options.positional_help("[optional args]");
|
||||
options
|
||||
.positional_help("[optional args]")
|
||||
.show_positional_help();
|
||||
|
||||
bool apple = false;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user