Fix an additional space in help generated (#377)
This commit is contained in:
parent
f087dc8fcd
commit
1dcb44e79a
@ -2742,7 +2742,12 @@ Options::help(const std::vector<std::string>& help_groups, bool print_usage) con
|
|||||||
String result = m_help_string;
|
String result = m_help_string;
|
||||||
if(print_usage)
|
if(print_usage)
|
||||||
{
|
{
|
||||||
result+= "\nUsage:\n " + toLocalString(m_program) + " " + toLocalString(m_custom_help);
|
result+= "\nUsage:\n " + toLocalString(m_program);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_custom_help.empty())
|
||||||
|
{
|
||||||
|
result += " " + toLocalString(m_custom_help);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_positional.empty() && !m_positional_help.empty()) {
|
if (!m_positional.empty() && !m_positional_help.empty()) {
|
||||||
|
@ -918,3 +918,27 @@ TEST_CASE("Iterator", "[iterator]") {
|
|||||||
|
|
||||||
REQUIRE(++iter == result.end());
|
REQUIRE(++iter == result.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("No Options help", "[options]")
|
||||||
|
{
|
||||||
|
std::vector<std::string> positional;
|
||||||
|
|
||||||
|
cxxopts::Options options("test", "test no options help");
|
||||||
|
|
||||||
|
// explicitly setting custom help empty to overwrite
|
||||||
|
// default "[OPTION...]" when there are no options
|
||||||
|
options.positional_help("<posArg1>...<posArgN>")
|
||||||
|
.custom_help("")
|
||||||
|
.add_options()
|
||||||
|
("positional", "", cxxopts::value<std::vector<std::string>>(positional));
|
||||||
|
|
||||||
|
Argv av({"test", "posArg1", "posArg2", "posArg3"});
|
||||||
|
|
||||||
|
auto argc = av.argc();
|
||||||
|
auto** argv = av.argv();
|
||||||
|
|
||||||
|
options.parse_positional({"positional"});
|
||||||
|
|
||||||
|
CHECK_NOTHROW(options.parse(argc, argv));
|
||||||
|
CHECK(options.help().find("test <posArg1>...<posArgN>") != std::string::npos);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user