Skip to content

Commit

Permalink
Fix missing opt argument hint from usage text.
Browse files Browse the repository at this point in the history
Fixes #35
  • Loading branch information
grafikrobot committed Aug 30, 2020
1 parent 85332b0 commit cb731a5
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 29 deletions.
6 changes: 4 additions & 2 deletions data/single_include/lyra/lyra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#define LYRA_VERSION_MAJOR 1
#define LYRA_VERSION_MINOR 5
#define LYRA_VERSION_PATCH 0
#define LYRA_VERSION_PATCH 1

#define LYRA_VERSION \
(((LYRA_VERSION_MAJOR)*10000000) + ((LYRA_VERSION_MINOR)*100000) \
Expand Down Expand Up @@ -3230,6 +3230,7 @@ class opt : public bound_parser<opt>
if (o > 0) result += "|";
result += opt_names[o];
}
if (!m_hint.empty()) result += " <" + m_hint + ">";
return result;
}

Expand All @@ -3252,7 +3253,8 @@ class opt : public bound_parser<opt>
virtual bool is_named(const std::string & n) const override
{
return bound_parser::is_named(n)
|| (std::find(opt_names.begin(), opt_names.end(), n) != opt_names.end());
|| (std::find(opt_names.begin(), opt_names.end(), n)
!= opt_names.end());
}

bool isMatch(
Expand Down
5 changes: 5 additions & 0 deletions docs/lyra.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ include::../include/lyra/val.hpp[tag=reference]
== History
=== 1.5.1
Minor change to bring back the missing option argument hints from the usage
help output.
=== 1.5
This release has some big changes in easy of use and functionality. There are
Expand Down
32 changes: 20 additions & 12 deletions docs/lyra.html
Original file line number Diff line number Diff line change
Expand Up @@ -494,12 +494,13 @@ <h1>Lyra</h1>
</li>
<li><a href="#_history">12. History</a>
<ul class="sectlevel2">
<li><a href="#_1_5">12.1. 1.5</a></li>
<li><a href="#_1_4">12.2. 1.4</a></li>
<li><a href="#_1_3">12.3. 1.3</a></li>
<li><a href="#_1_2">12.4. 1.2</a></li>
<li><a href="#_1_1">12.5. 1.1</a></li>
<li><a href="#_1_0">12.6. 1.0</a></li>
<li><a href="#_1_5_1">12.1. 1.5.1</a></li>
<li><a href="#_1_5">12.2. 1.5</a></li>
<li><a href="#_1_4">12.3. 1.4</a></li>
<li><a href="#_1_3">12.4. 1.3</a></li>
<li><a href="#_1_2">12.5. 1.2</a></li>
<li><a href="#_1_1">12.6. 1.1</a></li>
<li><a href="#_1_0">12.7. 1.0</a></li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -2368,7 +2369,14 @@ <h3 id="lyra_val"><a class="anchor" href="#lyra_val"></a>11.18. <code>lyra::val<
<h2 id="_history"><a class="anchor" href="#_history"></a>12. History</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_1_5"><a class="anchor" href="#_1_5"></a>12.1. 1.5</h3>
<h3 id="_1_5_1"><a class="anchor" href="#_1_5_1"></a>12.1. 1.5.1</h3>
<div class="paragraph">
<p>Minor change to bring back the missing option argument hints from the usage
help output.</p>
</div>
</div>
<div class="sect2">
<h3 id="_1_5"><a class="anchor" href="#_1_5"></a>12.2. 1.5</h3>
<div class="paragraph">
<p>This release has some big changes in easy of use and functionality. There are
now alternate interfaces for specifying and fetching arguments. Also the help
Expand Down Expand Up @@ -2460,7 +2468,7 @@ <h3 id="_1_5"><a class="anchor" href="#_1_5"></a>12.1. 1.5</h3>
</div>
</div>
<div class="sect2">
<h3 id="_1_4"><a class="anchor" href="#_1_4"></a>12.2. 1.4</h3>
<h3 id="_1_4"><a class="anchor" href="#_1_4"></a>12.3. 1.4</h3>
<div class="paragraph">
<p>Changes:</p>
</div>
Expand Down Expand Up @@ -2494,7 +2502,7 @@ <h3 id="_1_4"><a class="anchor" href="#_1_4"></a>12.2. 1.4</h3>
</div>
</div>
<div class="sect2">
<h3 id="_1_3"><a class="anchor" href="#_1_3"></a>12.3. 1.3</h3>
<h3 id="_1_3"><a class="anchor" href="#_1_3"></a>12.4. 1.3</h3>
<div class="paragraph">
<p>Changes:</p>
</div>
Expand Down Expand Up @@ -2539,7 +2547,7 @@ <h3 id="_1_3"><a class="anchor" href="#_1_3"></a>12.3. 1.3</h3>
</div>
</div>
<div class="sect2">
<h3 id="_1_2"><a class="anchor" href="#_1_2"></a>12.4. 1.2</h3>
<h3 id="_1_2"><a class="anchor" href="#_1_2"></a>12.5. 1.2</h3>
<div class="paragraph">
<p>Changes:</p>
</div>
Expand Down Expand Up @@ -2585,7 +2593,7 @@ <h3 id="_1_2"><a class="anchor" href="#_1_2"></a>12.4. 1.2</h3>
</div>
</div>
<div class="sect2">
<h3 id="_1_1"><a class="anchor" href="#_1_1"></a>12.5. 1.1</h3>
<h3 id="_1_1"><a class="anchor" href="#_1_1"></a>12.6. 1.1</h3>
<div class="paragraph">
<p>Changes:</p>
</div>
Expand Down Expand Up @@ -2630,7 +2638,7 @@ <h3 id="_1_1"><a class="anchor" href="#_1_1"></a>12.5. 1.1</h3>
</div>
</div>
<div class="sect2">
<h3 id="_1_0"><a class="anchor" href="#_1_0"></a>12.6. 1.0</h3>
<h3 id="_1_0"><a class="anchor" href="#_1_0"></a>12.7. 1.0</h3>
<div class="paragraph">
<p>This is the initial base version based on Clara library. Changes from that
library:</p>
Expand Down
4 changes: 3 additions & 1 deletion include/lyra/opt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class opt : public bound_parser<opt>
if (o > 0) result += "|";
result += opt_names[o];
}
if (!m_hint.empty()) result += " <" + m_hint + ">";
return result;
}

Expand All @@ -113,7 +114,8 @@ class opt : public bound_parser<opt>
virtual bool is_named(const std::string & n) const override
{
return bound_parser::is_named(n)
|| (std::find(opt_names.begin(), opt_names.end(), n) != opt_names.end());
|| (std::find(opt_names.begin(), opt_names.end(), n)
!= opt_names.end());
}

bool isMatch(
Expand Down
2 changes: 1 addition & 1 deletion include/lyra/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#define LYRA_VERSION_MAJOR 1
#define LYRA_VERSION_MINOR 5
#define LYRA_VERSION_PATCH 0
#define LYRA_VERSION_PATCH 1

#define LYRA_VERSION \
(((LYRA_VERSION_MAJOR)*10000000) + ((LYRA_VERSION_MINOR)*100000) \
Expand Down
2 changes: 1 addition & 1 deletion tests/required_run_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int main()
auto result = cli.parse({ "TestApp", "--number", "42" });
test
(REQUIRE(!result))
(REQUIRE(result.errorMessage() == "Expected: --name"));
(REQUIRE(result.errorMessage() == "Expected: --name <name>"));
}

return test;
Expand Down
34 changes: 22 additions & 12 deletions tests/usage_text_run_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Distributed under the Boost Software License, Version 1.0.
http://www.boost.org/LICENSE_1_0.txt)
*/

#include <lyra/lyra.hpp>
#include "mini_test.hpp"
#include <string>
#include <lyra/lyra.hpp>
#include <sstream>
#include <string>

int main()
{
Expand All @@ -18,24 +18,34 @@ int main()
{
bool a = false;
bool show_help = false;
auto cli = lyra::cli() | opt( a )["-a"] | help(show_help);
auto cli = lyra::cli() | opt(a)["-a"] | help(show_help);
std::ostringstream help_text;
auto result = cli.parse( { "TestApp", "-?" } );
auto result = cli.parse({ "TestApp", "-?" });
help_text << cli;
test
(REQUIRE( result ))
(REQUIRE( help_text.str().find("USAGE:") != std::string::npos ));
test(REQUIRE(result));
test(REQUIRE(help_text.str().find("USAGE:") != std::string::npos));
}
{
bool a = false;
bool show_help = false;
auto cli = lyra::cli() | opt( a )["-a"] | help(show_help);
auto cli = lyra::cli() | opt(a)["-a"] | help(show_help);
std::ostringstream help_text;
auto result = cli.parse( { "", "-?" } );
auto result = cli.parse({ "", "-?" });
help_text << cli;
test
(REQUIRE( result ))
(REQUIRE( help_text.str().find("USAGE:") == std::string::npos ));
test(REQUIRE(result));
test(REQUIRE(help_text.str().find("USAGE:") == std::string::npos));
}
{
std::string named_required;
auto opt_required
= lyra::opt(named_required, "required-arg")["--required"](
"You must supply this arg");
test(REQUIRE(
opt_required.get_usage_text().find("--required")
!= std::string::npos));
test(REQUIRE(
opt_required.get_usage_text().find("<required-arg>")
!= std::string::npos));
}

return test;
Expand Down

0 comments on commit cb731a5

Please sign in to comment.