Skip to content

Commit 1dcb44e

Browse files
authored
Fix an additional space in help generated (#377)
1 parent f087dc8 commit 1dcb44e

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

include/cxxopts.hpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -2742,7 +2742,12 @@ Options::help(const std::vector<std::string>& help_groups, bool print_usage) con
27422742
String result = m_help_string;
27432743
if(print_usage)
27442744
{
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);
27462751
}
27472752

27482753
if (!m_positional.empty() && !m_positional_help.empty()) {

test/options.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -918,3 +918,27 @@ TEST_CASE("Iterator", "[iterator]") {
918918

919919
REQUIRE(++iter == result.end());
920920
}
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+
}

0 commit comments

Comments
 (0)