Commit 1dcb44e79a17e703e024594487b3a442d87e4741
Committed by
GitHub
1 parent
f087dc8f
Fix an additional space in help generated (#377)
Showing
2 changed files
with
30 additions
and
1 deletions
include/cxxopts.hpp
| ... | ... | @@ -2742,7 +2742,12 @@ Options::help(const std::vector<std::string>& help_groups, bool print_usage) con |
| 2742 | 2742 | String result = m_help_string; |
| 2743 | 2743 | if(print_usage) |
| 2744 | 2744 | { |
| 2745 | - result+= "\nUsage:\n " + toLocalString(m_program) + " " + toLocalString(m_custom_help); | |
| 2745 | + result+= "\nUsage:\n " + toLocalString(m_program); | |
| 2746 | + } | |
| 2747 | + | |
| 2748 | + if (!m_custom_help.empty()) | |
| 2749 | + { | |
| 2750 | + result += " " + toLocalString(m_custom_help); | |
| 2746 | 2751 | } |
| 2747 | 2752 | |
| 2748 | 2753 | if (!m_positional.empty() && !m_positional_help.empty()) { | ... | ... |
test/options.cpp
| ... | ... | @@ -918,3 +918,27 @@ TEST_CASE("Iterator", "[iterator]") { |
| 918 | 918 | |
| 919 | 919 | REQUIRE(++iter == result.end()); |
| 920 | 920 | } |
| 921 | + | |
| 922 | +TEST_CASE("No Options help", "[options]") | |
| 923 | +{ | |
| 924 | + std::vector<std::string> positional; | |
| 925 | + | |
| 926 | + cxxopts::Options options("test", "test no options help"); | |
| 927 | + | |
| 928 | + // explicitly setting custom help empty to overwrite | |
| 929 | + // default "[OPTION...]" when there are no options | |
| 930 | + options.positional_help("<posArg1>...<posArgN>") | |
| 931 | + .custom_help("") | |
| 932 | + .add_options() | |
| 933 | + ("positional", "", cxxopts::value<std::vector<std::string>>(positional)); | |
| 934 | + | |
| 935 | + Argv av({"test", "posArg1", "posArg2", "posArg3"}); | |
| 936 | + | |
| 937 | + auto argc = av.argc(); | |
| 938 | + auto** argv = av.argv(); | |
| 939 | + | |
| 940 | + options.parse_positional({"positional"}); | |
| 941 | + | |
| 942 | + CHECK_NOTHROW(options.parse(argc, argv)); | |
| 943 | + CHECK(options.help().find("test <posArg1>...<posArgN>") != std::string::npos); | |
| 944 | +} | ... | ... |