Allow help string to be customised
Fixes #82. This allows the help string after the program name to be completely replaced by the user.
This commit is contained in:
parent
2ca68adeaf
commit
5b774d7a7e
@ -95,6 +95,12 @@ overridden. The effect is that writing `-o` by itself will set option `o` to
|
|||||||
`true`. However, they can also be written with various strings using either
|
`true`. However, they can also be written with various strings using either
|
||||||
`=value` or the next argument.
|
`=value` or the next argument.
|
||||||
|
|
||||||
|
## Custom help
|
||||||
|
|
||||||
|
The string after the program name on the first line of the help can be
|
||||||
|
completely replaced by calling `options.custom_help`. Note that you might
|
||||||
|
also want to override the positional help by calling `options.positional_help`.
|
||||||
|
|
||||||
# Linking
|
# Linking
|
||||||
|
|
||||||
This is a header only library.
|
This is a header only library.
|
||||||
|
|||||||
@ -1167,6 +1167,7 @@ namespace cxxopts
|
|||||||
Options(std::string program, std::string help_string = "")
|
Options(std::string program, std::string help_string = "")
|
||||||
: m_program(std::move(program))
|
: m_program(std::move(program))
|
||||||
, m_help_string(toLocalString(std::move(help_string)))
|
, m_help_string(toLocalString(std::move(help_string)))
|
||||||
|
, m_custom_help("[OPTION...]")
|
||||||
, m_positional_help("positional parameters")
|
, m_positional_help("positional parameters")
|
||||||
, m_show_positional(false)
|
, m_show_positional(false)
|
||||||
, m_next_positional(m_positional.end())
|
, m_next_positional(m_positional.end())
|
||||||
@ -1180,6 +1181,13 @@ namespace cxxopts
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Options&
|
||||||
|
custom_help(std::string help_text)
|
||||||
|
{
|
||||||
|
m_custom_help = std::move(help_text);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
Options&
|
Options&
|
||||||
show_positional_help()
|
show_positional_help()
|
||||||
{
|
{
|
||||||
@ -1247,6 +1255,7 @@ namespace cxxopts
|
|||||||
|
|
||||||
std::string m_program;
|
std::string m_program;
|
||||||
String m_help_string;
|
String m_help_string;
|
||||||
|
std::string m_custom_help;
|
||||||
std::string m_positional_help;
|
std::string m_positional_help;
|
||||||
bool m_show_positional;
|
bool m_show_positional;
|
||||||
|
|
||||||
@ -1928,9 +1937,9 @@ std::string
|
|||||||
Options::help(const std::vector<std::string>& help_groups) const
|
Options::help(const std::vector<std::string>& help_groups) const
|
||||||
{
|
{
|
||||||
String result = m_help_string + "\nUsage:\n " +
|
String result = m_help_string + "\nUsage:\n " +
|
||||||
toLocalString(m_program) + " [OPTION...]";
|
toLocalString(m_program) + " " + toLocalString(m_custom_help);
|
||||||
|
|
||||||
if (m_positional.size() > 0) {
|
if (m_positional.size() > 0 && m_positional_help.size() > 0) {
|
||||||
result += " " + toLocalString(m_positional_help);
|
result += " " + toLocalString(m_positional_help);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user