From 4aa95505ded43e663fd9dae61c49b08fdc6cce0c Mon Sep 17 00:00:00 2001 From: "Maarten L. Hekkelman" Date: Tue, 24 Jan 2023 21:02:12 +0100 Subject: [PATCH] simple get, without templates --- CMakeLists.txt | 2 +- changelog | 3 +++ include/mcfp/mcfp.hpp | 10 ++++++++++ test/unit-test.cpp | 19 +++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f093764..291787a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ cmake_minimum_required(VERSION 3.16) # set the project name -project(libmcfp VERSION 1.2.3 LANGUAGES CXX) +project(libmcfp VERSION 1.2.4 LANGUAGES CXX) include(GNUInstallDirs) include(CMakePackageConfigHelpers) diff --git a/changelog b/changelog index b312157..3f9a787 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +Version 1.2.4 +- Simpler get (added a version without template arguments) + Version 1.2.3 - MSVC compatibility diff --git a/include/mcfp/mcfp.hpp b/include/mcfp/mcfp.hpp index 79ec051..5dec155 100644 --- a/include/mcfp/mcfp.hpp +++ b/include/mcfp/mcfp.hpp @@ -509,6 +509,16 @@ class config return result; } + std::string get(std::string_view name) const + { + return get(name); + } + + std::string get(std::string_view name, std::error_code &ec) const + { + return get(name, ec); + } + const std::vector &operands() const { return m_impl->m_operands; diff --git a/test/unit-test.cpp b/test/unit-test.cpp index c897d0d..e408b6b 100644 --- a/test/unit-test.cpp +++ b/test/unit-test.cpp @@ -368,6 +368,25 @@ BOOST_AUTO_TEST_CASE(t_12) BOOST_CHECK(not ec); } +BOOST_AUTO_TEST_CASE(t_13) +{ + const char *const argv[] = { + "test", "--test=bla", nullptr + }; + int argc = sizeof(argv) / sizeof(char*) - 1; + + auto &config = mcfp::config::instance(); + + config.init( + "test [options]", + mcfp::make_option("test", "")); + + BOOST_CHECK_NO_THROW(config.parse(argc, argv)); + + BOOST_TEST(config.has("test")); + BOOST_TEST(config.get("test") == "bla"); +} + // -------------------------------------------------------------------- BOOST_AUTO_TEST_CASE(file_1, * utf::tolerance(0.001))