[med-svn] [Git][med-team/libargs][upstream] New upstream version 6.2.3
Andreas Tille
gitlab at salsa.debian.org
Sun Oct 18 19:59:08 BST 2020
Andreas Tille pushed to branch upstream at Debian Med / libargs
Commits:
18cb1e9c by Andreas Tille at 2020-10-18T20:53:39+02:00
New upstream version 6.2.3
- - - - -
5 changed files:
- CMakeLists.txt
- args.hxx
- + meson.build
- + meson_options.txt
- test.cxx
Changes:
=====================================
CMakeLists.txt
=====================================
@@ -26,7 +26,16 @@ option(ARGS_BUILD_EXAMPLE "Build example" ON)
option(ARGS_BUILD_UNITTESTS "Build unittests" ON)
add_library(args INTERFACE)
-target_include_directories(args INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")
+target_include_directories(args INTERFACE
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
+ $<INSTALL_INTERFACE:include>)
+
+install(FILES args.hxx DESTINATION include)
+install(TARGETS args EXPORT args-targets)
+install(EXPORT args-targets
+ FILE args-config.cmake
+ NAMESPACE taywee::
+ DESTINATION lib/cmake/args)
if (ARGS_BUILD_EXAMPLE)
add_executable(gitlike examples/gitlike.cxx)
=====================================
args.hxx
=====================================
@@ -1,4 +1,8 @@
-/* Copyright (c) 2016-2017 Taylor C. Richberger <taywee at gmx.com> and Pavel
+/* A simple header-only C++ argument parser library.
+ *
+ * https://github.com/Taywee/args
+ *
+ * Copyright (c) 2016-2020 Taylor C. Richberger <taywee at gmx.com> and Pavel
* Belikov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -29,6 +33,11 @@
#ifndef ARGS_HXX
#define ARGS_HXX
+#define ARGS_VERSION "6.2.3"
+#define ARGS_VERSION_MAJOR 6
+#define ARGS_VERSION_MINOR 2
+#define ARGS_VERSION_PATCH 3
+
#include <algorithm>
#include <iterator>
#include <exception>
@@ -40,6 +49,11 @@
#include <unordered_map>
#include <unordered_set>
#include <type_traits>
+#include <cstddef>
+
+#if defined(_MSC_VER) && _MSC_VER <= 1800
+#define noexcept
+#endif
#ifdef ARGS_TESTNAMESPACE
namespace argstest
@@ -1002,11 +1016,29 @@ namespace args
namespace detail
{
- template <typename T, typename = int>
- struct IsConvertableToString : std::false_type {};
+ template<typename T>
+ using vector = std::vector<T, std::allocator<T>>;
+
+ template<typename K, typename T>
+ using unordered_map = std::unordered_map<K, T, std::hash<K>,
+ std::equal_to<K>, std::allocator<std::pair<const K, T> > >;
+
+ template<typename S, typename T>
+ class is_streamable
+ {
+ template<typename SS, typename TT>
+ static auto test(int)
+ -> decltype( std::declval<SS&>() << std::declval<TT>(), std::true_type() );
+
+ template<typename, typename>
+ static auto test(...) -> std::false_type;
+
+ public:
+ using type = decltype(test<S,T>(0));
+ };
template <typename T>
- struct IsConvertableToString<T, decltype(std::declval<std::ostringstream&>() << std::declval<T>(), int())> : std::true_type {};
+ using IsConvertableToString = typename is_streamable<std::ostringstream, T>::type;
template <typename T>
typename std::enable_if<IsConvertableToString<T>::value, std::string>::type
@@ -1470,7 +1502,9 @@ namespace args
*/
std::vector<Base *>::size_type MatchedChildren() const
{
- return std::count_if(std::begin(Children()), std::end(Children()), [](const Base *child){return child->Matched();});
+ // Cast to avoid warnings from -Wsign-conversion
+ return static_cast<std::vector<Base *>::size_type>(
+ std::count_if(std::begin(Children()), std::end(Children()), [](const Base *child){return child->Matched();}));
}
/** Whether or not this group matches validation
@@ -1630,11 +1664,11 @@ namespace args
public:
Subparser(std::vector<std::string> args_, ArgumentParser &parser_, const Command &command_, const HelpParams &helpParams_)
- : args(std::move(args_)), parser(&parser_), helpParams(helpParams_), command(command_)
+ : Group({}, Validators::AllChildGroups), args(std::move(args_)), parser(&parser_), helpParams(helpParams_), command(command_)
{
}
- Subparser(const Command &command_, const HelpParams &helpParams_) : helpParams(helpParams_), command(command_)
+ Subparser(const Command &command_, const HelpParams &helpParams_) : Group({}, Validators::AllChildGroups), helpParams(helpParams_), command(command_)
{
}
@@ -2125,18 +2159,23 @@ namespace args
return;
}
- for (Base *child: Children())
+ auto onValidationError = [&]
{
- if (child->IsGroup() && !child->Matched())
- {
- std::ostringstream problem;
- problem << "Group validation failed somewhere!";
+ std::ostringstream problem;
+ problem << "Group validation failed somewhere!";
#ifdef ARGS_NOEXCEPT
- error = Error::Validation;
- errorMsg = problem.str();
+ error = Error::Validation;
+ errorMsg = problem.str();
#else
- throw ValidationError(problem.str());
+ throw ValidationError(problem.str());
#endif
+ };
+
+ for (Base *child: Children())
+ {
+ if (child->IsGroup() && !child->Matched())
+ {
+ onValidationError();
}
child->Validate(shortprefix, longprefix);
@@ -2145,6 +2184,10 @@ namespace args
if (subparser != nullptr)
{
subparser->Validate(shortprefix, longprefix);
+ if (!subparser->Matched())
+ {
+ onValidationError();
+ }
}
if (selectedCommand == nullptr && commandIsRequired && (Group::HasCommand() || subparserHasCommand))
@@ -2697,7 +2740,7 @@ namespace args
#endif
readCompletion = true;
++it;
- size_t argsLeft = std::distance(it, end);
+ const auto argsLeft = static_cast<size_t>(std::distance(it, end));
if (completion->cword == 0 || argsLeft <= 1 || completion->cword >= argsLeft)
{
#ifndef ARGS_NOEXCEPT
@@ -2716,13 +2759,15 @@ namespace args
if (idx > 0 && curArgs[idx] == "=")
{
curArgs[idx - 1] += "=";
+ // Avoid warnings from -Wsign-conversion
+ const auto signedIdx = static_cast<std::ptrdiff_t>(idx);
if (idx + 1 < curArgs.size())
{
curArgs[idx - 1] += curArgs[idx + 1];
- curArgs.erase(curArgs.begin() + idx, curArgs.begin() + idx + 2);
+ curArgs.erase(curArgs.begin() + signedIdx, curArgs.begin() + signedIdx + 2);
} else
{
- curArgs.erase(curArgs.begin() + idx);
+ curArgs.erase(curArgs.begin() + signedIdx);
}
} else
{
@@ -3251,9 +3296,14 @@ namespace args
operator ()(const std::string &name, const std::string &value, T &destination)
{
std::istringstream ss(value);
- ss >> destination >> std::ws;
+ bool failed = !(ss >> destination);
+
+ if (!failed)
+ {
+ ss >> std::ws;
+ }
- if (ss.rdbuf()->in_avail() > 0)
+ if (ss.rdbuf()->in_avail() > 0 || failed)
{
#ifdef ARGS_NOEXCEPT
(void)name;
@@ -3407,7 +3457,7 @@ namespace args
*/
template <
typename T,
- template <typename...> class List = std::vector,
+ template <typename...> class List = detail::vector,
typename Reader = ValueReader>
class NargsValueFlag : public FlagBase
{
@@ -3527,7 +3577,7 @@ namespace args
*/
template <
typename T,
- template <typename...> class List = std::vector,
+ template <typename...> class List = detail::vector,
typename Reader = ValueReader>
class ValueFlagList : public ValueFlagBase
{
@@ -3647,7 +3697,7 @@ namespace args
typename K,
typename T,
typename Reader = ValueReader,
- template <typename...> class Map = std::unordered_map>
+ template <typename...> class Map = detail::unordered_map>
class MapFlag : public ValueFlagBase
{
private:
@@ -3734,9 +3784,9 @@ namespace args
template <
typename K,
typename T,
- template <typename...> class List = std::vector,
+ template <typename...> class List = detail::vector,
typename Reader = ValueReader,
- template <typename...> class Map = std::unordered_map>
+ template <typename...> class Map = detail::unordered_map>
class MapFlagList : public ValueFlagBase
{
private:
@@ -3925,7 +3975,7 @@ namespace args
*/
template <
typename T,
- template <typename...> class List = std::vector,
+ template <typename...> class List = detail::vector,
typename Reader = ValueReader>
class PositionalList : public PositionalBase
{
@@ -4046,7 +4096,7 @@ namespace args
typename K,
typename T,
typename Reader = ValueReader,
- template <typename...> class Map = std::unordered_map>
+ template <typename...> class Map = detail::unordered_map>
class MapPositional : public PositionalBase
{
private:
@@ -4126,9 +4176,9 @@ namespace args
template <
typename K,
typename T,
- template <typename...> class List = std::vector,
+ template <typename...> class List = detail::vector,
typename Reader = ValueReader,
- template <typename...> class Map = std::unordered_map>
+ template <typename...> class Map = detail::unordered_map>
class MapPositionalList : public PositionalBase
{
private:
=====================================
meson.build
=====================================
@@ -0,0 +1,37 @@
+project('args.hxx', ['cpp'],
+ version: '6.2.2',
+ default_options: 'cpp_std=c++11',
+ license: 'MIT'
+)
+
+# This is a header-only lib, all we need to do is include it
+args_dep = declare_dependency(
+ include_directories: include_directories('.')
+).as_system('system')
+
+install_headers('args.hxx')
+
+# examples
+if get_option('examples')
+executable('gitlike', sources: 'examples/gitlike.cxx', dependencies: args_dep)
+executable('completion', sources: 'examples/completion.cxx', dependencies: args_dep)
+endif
+
+# tests
+if get_option('unittests')
+test('argstest', executable('argstest',
+ sources: 'test.cxx',
+ dependencies: args_dep
+))
+
+test('argstest-multiple-inclusion', executable('argstest-multiple-inclusion',
+ sources: [ 'test/multiple_inclusion_1.cxx', 'test/multiple_inclusion_2.cxx' ],
+ dependencies: args_dep
+))
+
+test('argstest-windows-h', executable('argstest-windows-h',
+ sources: 'test/windows_h.cxx',
+ dependencies: args_dep
+))
+endif
+
=====================================
meson_options.txt
=====================================
@@ -0,0 +1,3 @@
+option('examples', description: 'Build examples', type: 'boolean', value: false)
+option('unittests', description: 'Build unit tests', type: 'boolean', value: false)
+
=====================================
test.cxx
=====================================
@@ -936,6 +936,25 @@ TEST_CASE("Subparser validation works as expected", "[args]")
REQUIRE_THROWS_AS(p.ParseArgs(std::vector<std::string>{"unknown-command"}), args::ParseError);
}
+TEST_CASE("Subparser group validation works as expected", "[args]")
+{
+ int x = 0;
+ args::ArgumentParser p("parser");
+ args::Command a(p, "a", "command a", [&](args::Subparser &s)
+ {
+ args::Group required(s, "", args::Group::Validators::All);
+ args::ValueFlag<std::string> f(required, "", "", {'f'});
+ s.Parse();
+ ++x;
+ });
+
+ p.RequireCommand(false);
+ REQUIRE_NOTHROW(p.ParseArgs(std::vector<std::string>{}));
+ REQUIRE_NOTHROW(p.ParseArgs(std::vector<std::string>{"a", "-f", "F"}));
+ REQUIRE_THROWS_AS(p.ParseArgs(std::vector<std::string>{"a"}), args::ValidationError);
+ REQUIRE(x == 1);
+}
+
TEST_CASE("Global options work as expected", "[args]")
{
args::Group globals;
@@ -1173,6 +1192,8 @@ TEST_CASE("ValueParser works as expected", "[args]")
args::ValueFlag<std::string> f(p, "name", "description", {'f'});
args::ValueFlag<StringAssignable> b(p, "name", "description", {'b'});
args::ValueFlag<int> i(p, "name", "description", {'i'});
+ args::ValueFlag<int> d(p, "name", "description", {'d'});
+ args::PositionalList<double> ds(p, "name", "description");
REQUIRE_NOTHROW(p.ParseArgs(std::vector<std::string>{"-f", "a b"}));
REQUIRE(args::get(f) == "a b");
@@ -1185,6 +1206,11 @@ TEST_CASE("ValueParser works as expected", "[args]")
REQUIRE_NOTHROW(p.ParseArgs(std::vector<std::string>{"-i", " 12"}));
REQUIRE(args::get(i) == 12);
+
+ REQUIRE_THROWS_AS(p.ParseArgs(std::vector<std::string>{"-i", "a"}), args::ParseError);
+ REQUIRE_THROWS_AS(p.ParseArgs(std::vector<std::string>{"-d", "b"}), args::ParseError);
+ REQUIRE_THROWS_AS(p.ParseArgs(std::vector<std::string>{"c"}), args::ParseError);
+ REQUIRE_THROWS_AS(p.ParseArgs(std::vector<std::string>{"s"}), args::ParseError);
}
TEST_CASE("ActionFlag works as expected", "[args]")
View it on GitLab: https://salsa.debian.org/med-team/libargs/-/commit/18cb1e9ce25ee308ad90ad8301950d92d1feaa59
--
View it on GitLab: https://salsa.debian.org/med-team/libargs/-/commit/18cb1e9ce25ee308ad90ad8301950d92d1feaa59
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20201018/14eb5725/attachment-0001.html>
More information about the debian-med-commit
mailing list