From cb731a5e8613a454d4e526cdd740fe945a4e2396 Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Sat, 29 Aug 2020 21:51:30 -0500 Subject: [PATCH] Fix missing opt argument hint from usage text. Fixes #35 --- data/single_include/lyra/lyra.hpp | 6 ++++-- docs/lyra.adoc | 5 +++++ docs/lyra.html | 32 ++++++++++++++++++----------- include/lyra/opt.hpp | 4 +++- include/lyra/version.hpp | 2 +- tests/required_run_test.cpp | 2 +- tests/usage_text_run_test.cpp | 34 ++++++++++++++++++++----------- 7 files changed, 56 insertions(+), 29 deletions(-) diff --git a/data/single_include/lyra/lyra.hpp b/data/single_include/lyra/lyra.hpp index de80826..c866815 100644 --- a/data/single_include/lyra/lyra.hpp +++ b/data/single_include/lyra/lyra.hpp @@ -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) \ @@ -3230,6 +3230,7 @@ class opt : public bound_parser if (o > 0) result += "|"; result += opt_names[o]; } + if (!m_hint.empty()) result += " <" + m_hint + ">"; return result; } @@ -3252,7 +3253,8 @@ class opt : public bound_parser 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( diff --git a/docs/lyra.adoc b/docs/lyra.adoc index a4457a7..adde8e5 100644 --- a/docs/lyra.adoc +++ b/docs/lyra.adoc @@ -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 diff --git a/docs/lyra.html b/docs/lyra.html index 39c92a5..068053b 100644 --- a/docs/lyra.html +++ b/docs/lyra.html @@ -494,12 +494,13 @@

Lyra

  • 12. History
  • @@ -2368,7 +2369,14 @@

    11.18. lyra::val<

    12. History

    -

    12.1. 1.5

    +

    12.1. 1.5.1

    +
    +

    Minor change to bring back the missing option argument hints from the usage +help output.

    +
    +
    +
    +

    12.2. 1.5

    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 @@ -2460,7 +2468,7 @@

    12.1. 1.5

    -

    12.2. 1.4

    +

    12.3. 1.4

    Changes:

    @@ -2494,7 +2502,7 @@

    12.2. 1.4

    -

    12.3. 1.3

    +

    12.4. 1.3

    Changes:

    @@ -2539,7 +2547,7 @@

    12.3. 1.3

    -

    12.4. 1.2

    +

    12.5. 1.2

    Changes:

    @@ -2585,7 +2593,7 @@

    12.4. 1.2

    -

    12.5. 1.1

    +

    12.6. 1.1

    Changes:

    @@ -2630,7 +2638,7 @@

    12.5. 1.1

    -

    12.6. 1.0

    +

    12.7. 1.0

    This is the initial base version based on Clara library. Changes from that library:

    diff --git a/include/lyra/opt.hpp b/include/lyra/opt.hpp index 02162d2..b5fcd53 100644 --- a/include/lyra/opt.hpp +++ b/include/lyra/opt.hpp @@ -91,6 +91,7 @@ class opt : public bound_parser if (o > 0) result += "|"; result += opt_names[o]; } + if (!m_hint.empty()) result += " <" + m_hint + ">"; return result; } @@ -113,7 +114,8 @@ class opt : public bound_parser 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( diff --git a/include/lyra/version.hpp b/include/lyra/version.hpp index 852aac8..00255bb 100644 --- a/include/lyra/version.hpp +++ b/include/lyra/version.hpp @@ -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) \ diff --git a/tests/required_run_test.cpp b/tests/required_run_test.cpp index b475c92..4bb808d 100644 --- a/tests/required_run_test.cpp +++ b/tests/required_run_test.cpp @@ -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 ")); } return test; diff --git a/tests/usage_text_run_test.cpp b/tests/usage_text_run_test.cpp index 3361fdf..d75812a 100644 --- a/tests/usage_text_run_test.cpp +++ b/tests/usage_text_run_test.cpp @@ -5,10 +5,10 @@ Distributed under the Boost Software License, Version 1.0. http://www.boost.org/LICENSE_1_0.txt) */ -#include #include "mini_test.hpp" -#include +#include #include +#include int main() { @@ -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("") + != std::string::npos)); } return test;