Skip to content

Commit cb731a5

Browse files
committed
Fix missing opt argument hint from usage text.
Fixes #35
1 parent 85332b0 commit cb731a5

7 files changed

Lines changed: 56 additions & 29 deletions

File tree

data/single_include/lyra/lyra.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#define LYRA_VERSION_MAJOR 1
1515
#define LYRA_VERSION_MINOR 5
16-
#define LYRA_VERSION_PATCH 0
16+
#define LYRA_VERSION_PATCH 1
1717

1818
#define LYRA_VERSION \
1919
(((LYRA_VERSION_MAJOR)*10000000) + ((LYRA_VERSION_MINOR)*100000) \
@@ -3230,6 +3230,7 @@ class opt : public bound_parser<opt>
32303230
if (o > 0) result += "|";
32313231
result += opt_names[o];
32323232
}
3233+
if (!m_hint.empty()) result += " <" + m_hint + ">";
32333234
return result;
32343235
}
32353236

@@ -3252,7 +3253,8 @@ class opt : public bound_parser<opt>
32523253
virtual bool is_named(const std::string & n) const override
32533254
{
32543255
return bound_parser::is_named(n)
3255-
|| (std::find(opt_names.begin(), opt_names.end(), n) != opt_names.end());
3256+
|| (std::find(opt_names.begin(), opt_names.end(), n)
3257+
!= opt_names.end());
32563258
}
32573259

32583260
bool isMatch(

docs/lyra.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ include::../include/lyra/val.hpp[tag=reference]
288288
289289
== History
290290
291+
=== 1.5.1
292+
293+
Minor change to bring back the missing option argument hints from the usage
294+
help output.
295+
291296
=== 1.5
292297
293298
This release has some big changes in easy of use and functionality. There are

docs/lyra.html

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,13 @@ <h1>Lyra</h1>
494494
</li>
495495
<li><a href="#_history">12. History</a>
496496
<ul class="sectlevel2">
497-
<li><a href="#_1_5">12.1. 1.5</a></li>
498-
<li><a href="#_1_4">12.2. 1.4</a></li>
499-
<li><a href="#_1_3">12.3. 1.3</a></li>
500-
<li><a href="#_1_2">12.4. 1.2</a></li>
501-
<li><a href="#_1_1">12.5. 1.1</a></li>
502-
<li><a href="#_1_0">12.6. 1.0</a></li>
497+
<li><a href="#_1_5_1">12.1. 1.5.1</a></li>
498+
<li><a href="#_1_5">12.2. 1.5</a></li>
499+
<li><a href="#_1_4">12.3. 1.4</a></li>
500+
<li><a href="#_1_3">12.4. 1.3</a></li>
501+
<li><a href="#_1_2">12.5. 1.2</a></li>
502+
<li><a href="#_1_1">12.6. 1.1</a></li>
503+
<li><a href="#_1_0">12.7. 1.0</a></li>
503504
</ul>
504505
</li>
505506
</ul>
@@ -2368,7 +2369,14 @@ <h3 id="lyra_val"><a class="anchor" href="#lyra_val"></a>11.18. <code>lyra::val<
23682369
<h2 id="_history"><a class="anchor" href="#_history"></a>12. History</h2>
23692370
<div class="sectionbody">
23702371
<div class="sect2">
2371-
<h3 id="_1_5"><a class="anchor" href="#_1_5"></a>12.1. 1.5</h3>
2372+
<h3 id="_1_5_1"><a class="anchor" href="#_1_5_1"></a>12.1. 1.5.1</h3>
2373+
<div class="paragraph">
2374+
<p>Minor change to bring back the missing option argument hints from the usage
2375+
help output.</p>
2376+
</div>
2377+
</div>
2378+
<div class="sect2">
2379+
<h3 id="_1_5"><a class="anchor" href="#_1_5"></a>12.2. 1.5</h3>
23722380
<div class="paragraph">
23732381
<p>This release has some big changes in easy of use and functionality. There are
23742382
now alternate interfaces for specifying and fetching arguments. Also the help
@@ -2460,7 +2468,7 @@ <h3 id="_1_5"><a class="anchor" href="#_1_5"></a>12.1. 1.5</h3>
24602468
</div>
24612469
</div>
24622470
<div class="sect2">
2463-
<h3 id="_1_4"><a class="anchor" href="#_1_4"></a>12.2. 1.4</h3>
2471+
<h3 id="_1_4"><a class="anchor" href="#_1_4"></a>12.3. 1.4</h3>
24642472
<div class="paragraph">
24652473
<p>Changes:</p>
24662474
</div>
@@ -2494,7 +2502,7 @@ <h3 id="_1_4"><a class="anchor" href="#_1_4"></a>12.2. 1.4</h3>
24942502
</div>
24952503
</div>
24962504
<div class="sect2">
2497-
<h3 id="_1_3"><a class="anchor" href="#_1_3"></a>12.3. 1.3</h3>
2505+
<h3 id="_1_3"><a class="anchor" href="#_1_3"></a>12.4. 1.3</h3>
24982506
<div class="paragraph">
24992507
<p>Changes:</p>
25002508
</div>
@@ -2539,7 +2547,7 @@ <h3 id="_1_3"><a class="anchor" href="#_1_3"></a>12.3. 1.3</h3>
25392547
</div>
25402548
</div>
25412549
<div class="sect2">
2542-
<h3 id="_1_2"><a class="anchor" href="#_1_2"></a>12.4. 1.2</h3>
2550+
<h3 id="_1_2"><a class="anchor" href="#_1_2"></a>12.5. 1.2</h3>
25432551
<div class="paragraph">
25442552
<p>Changes:</p>
25452553
</div>
@@ -2585,7 +2593,7 @@ <h3 id="_1_2"><a class="anchor" href="#_1_2"></a>12.4. 1.2</h3>
25852593
</div>
25862594
</div>
25872595
<div class="sect2">
2588-
<h3 id="_1_1"><a class="anchor" href="#_1_1"></a>12.5. 1.1</h3>
2596+
<h3 id="_1_1"><a class="anchor" href="#_1_1"></a>12.6. 1.1</h3>
25892597
<div class="paragraph">
25902598
<p>Changes:</p>
25912599
</div>
@@ -2630,7 +2638,7 @@ <h3 id="_1_1"><a class="anchor" href="#_1_1"></a>12.5. 1.1</h3>
26302638
</div>
26312639
</div>
26322640
<div class="sect2">
2633-
<h3 id="_1_0"><a class="anchor" href="#_1_0"></a>12.6. 1.0</h3>
2641+
<h3 id="_1_0"><a class="anchor" href="#_1_0"></a>12.7. 1.0</h3>
26342642
<div class="paragraph">
26352643
<p>This is the initial base version based on Clara library. Changes from that
26362644
library:</p>

include/lyra/opt.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class opt : public bound_parser<opt>
9191
if (o > 0) result += "|";
9292
result += opt_names[o];
9393
}
94+
if (!m_hint.empty()) result += " <" + m_hint + ">";
9495
return result;
9596
}
9697

@@ -113,7 +114,8 @@ class opt : public bound_parser<opt>
113114
virtual bool is_named(const std::string & n) const override
114115
{
115116
return bound_parser::is_named(n)
116-
|| (std::find(opt_names.begin(), opt_names.end(), n) != opt_names.end());
117+
|| (std::find(opt_names.begin(), opt_names.end(), n)
118+
!= opt_names.end());
117119
}
118120

119121
bool isMatch(

include/lyra/version.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#define LYRA_VERSION_MAJOR 1
1010
#define LYRA_VERSION_MINOR 5
11-
#define LYRA_VERSION_PATCH 0
11+
#define LYRA_VERSION_PATCH 1
1212

1313
#define LYRA_VERSION \
1414
(((LYRA_VERSION_MAJOR)*10000000) + ((LYRA_VERSION_MINOR)*100000) \

tests/required_run_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ int main()
7575
auto result = cli.parse({ "TestApp", "--number", "42" });
7676
test
7777
(REQUIRE(!result))
78-
(REQUIRE(result.errorMessage() == "Expected: --name"));
78+
(REQUIRE(result.errorMessage() == "Expected: --name <name>"));
7979
}
8080

8181
return test;

tests/usage_text_run_test.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ Distributed under the Boost Software License, Version 1.0.
55
http://www.boost.org/LICENSE_1_0.txt)
66
*/
77

8-
#include <lyra/lyra.hpp>
98
#include "mini_test.hpp"
10-
#include <string>
9+
#include <lyra/lyra.hpp>
1110
#include <sstream>
11+
#include <string>
1212

1313
int main()
1414
{
@@ -18,24 +18,34 @@ int main()
1818
{
1919
bool a = false;
2020
bool show_help = false;
21-
auto cli = lyra::cli() | opt( a )["-a"] | help(show_help);
21+
auto cli = lyra::cli() | opt(a)["-a"] | help(show_help);
2222
std::ostringstream help_text;
23-
auto result = cli.parse( { "TestApp", "-?" } );
23+
auto result = cli.parse({ "TestApp", "-?" });
2424
help_text << cli;
25-
test
26-
(REQUIRE( result ))
27-
(REQUIRE( help_text.str().find("USAGE:") != std::string::npos ));
25+
test(REQUIRE(result));
26+
test(REQUIRE(help_text.str().find("USAGE:") != std::string::npos));
2827
}
2928
{
3029
bool a = false;
3130
bool show_help = false;
32-
auto cli = lyra::cli() | opt( a )["-a"] | help(show_help);
31+
auto cli = lyra::cli() | opt(a)["-a"] | help(show_help);
3332
std::ostringstream help_text;
34-
auto result = cli.parse( { "", "-?" } );
33+
auto result = cli.parse({ "", "-?" });
3534
help_text << cli;
36-
test
37-
(REQUIRE( result ))
38-
(REQUIRE( help_text.str().find("USAGE:") == std::string::npos ));
35+
test(REQUIRE(result));
36+
test(REQUIRE(help_text.str().find("USAGE:") == std::string::npos));
37+
}
38+
{
39+
std::string named_required;
40+
auto opt_required
41+
= lyra::opt(named_required, "required-arg")["--required"](
42+
"You must supply this arg");
43+
test(REQUIRE(
44+
opt_required.get_usage_text().find("--required")
45+
!= std::string::npos));
46+
test(REQUIRE(
47+
opt_required.get_usage_text().find("<required-arg>")
48+
!= std::string::npos));
3949
}
4050

4151
return test;

0 commit comments

Comments
 (0)