diff --git a/README.md b/README.md index cd869b8..e233154 100644 --- a/README.md +++ b/README.md @@ -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 `=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 This is a header only library. diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp index 4bf91b4..f0ecec1 100644 --- a/include/cxxopts.hpp +++ b/include/cxxopts.hpp @@ -1167,6 +1167,7 @@ namespace cxxopts Options(std::string program, std::string help_string = "") : m_program(std::move(program)) , m_help_string(toLocalString(std::move(help_string))) + , m_custom_help("[OPTION...]") , m_positional_help("positional parameters") , m_show_positional(false) , m_next_positional(m_positional.end()) @@ -1180,6 +1181,13 @@ namespace cxxopts return *this; } + Options& + custom_help(std::string help_text) + { + m_custom_help = std::move(help_text); + return *this; + } + Options& show_positional_help() { @@ -1247,6 +1255,7 @@ namespace cxxopts std::string m_program; String m_help_string; + std::string m_custom_help; std::string m_positional_help; bool m_show_positional; @@ -1928,9 +1937,9 @@ std::string Options::help(const std::vector& help_groups) const { 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); }