diff --git a/.stylua.toml b/.stylua.toml new file mode 100644 index 00000000..394e8846 --- /dev/null +++ b/.stylua.toml @@ -0,0 +1 @@ +indent_type = "Spaces" diff --git a/include/argparse/argparse.hpp b/include/argparse/argparse.hpp index 37d56470..b877e6fd 100644 --- a/include/argparse/argparse.hpp +++ b/include/argparse/argparse.hpp @@ -29,6 +29,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #pragma once + +#ifndef ARGPARSE_MODULE_USE_STD_MODULE #include #include #include @@ -53,6 +55,7 @@ SOFTWARE. #include #include #include +#endif namespace argparse { @@ -72,7 +75,7 @@ struct HasContainerTraits< decltype(std::declval().size())>> : std::true_type {}; template -static constexpr bool IsContainer = HasContainerTraits::value; +inline constexpr bool IsContainer = HasContainerTraits::value; template struct HasStreamableTraits : std::false_type {}; @@ -84,7 +87,7 @@ struct HasStreamableTraits< : std::true_type {}; template -static constexpr bool IsStreamable = HasStreamableTraits::value; +inline constexpr bool IsStreamable = HasStreamableTraits::value; constexpr std::size_t repr_max_container_size = 5; diff --git a/module/argparse.cppm b/module/argparse.cppm new file mode 100644 index 00000000..625283e1 --- /dev/null +++ b/module/argparse.cppm @@ -0,0 +1,56 @@ +/* + __ _ _ __ __ _ _ __ __ _ _ __ ___ ___ + / _` | '__/ _` | '_ \ / _` | '__/ __|/ _ \ Argument Parser for Modern C++ +| (_| | | | (_| | |_) | (_| | | \__ \ __/ http://github.com/p-ranav/argparse + \__,_|_| \__, | .__/ \__,_|_| |___/\___| + |___/|_| + +Licensed under the MIT License . +SPDX-License-Identifier: MIT +Copyright (c) 2019-2022 Pranav Srinivas Kumar +and other contributors. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +module; + +#ifndef ARGPARSE_MODULE_USE_STD_MODULE +#include +#endif + +export module argparse; + +#ifdef ARGPARSE_MODULE_USE_STD_MODULE +import std; + +extern "C++" { +#include +} +#endif + + +export namespace argparse { + using argparse::nargs_pattern; + using argparse::default_arguments; + using argparse::operator&; + using argparse::Argument; + using argparse::ArgumentParser; +} + diff --git a/test/argparse_details.cppm b/test/argparse_details.cppm new file mode 100644 index 00000000..1c1668de --- /dev/null +++ b/test/argparse_details.cppm @@ -0,0 +1,10 @@ +module; + +#include + +export module argparse.details; + +export namespace argparse::details { + using argparse::details::repr; +} + diff --git a/test/test_actions.cpp b/test/test_actions.cpp index 07f59c99..aa8cd3de 100644 --- a/test/test_actions.cpp +++ b/test/test_actions.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include using doctest::test_suite; diff --git a/test/test_append.cpp b/test/test_append.cpp index 49345146..0114f719 100644 --- a/test/test_append.cpp +++ b/test/test_append.cpp @@ -1,6 +1,13 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include +#include +#include + using doctest::test_suite; TEST_CASE("Simplest .append" * test_suite("append")) { diff --git a/test/test_as_container.cpp b/test/test_as_container.cpp index 2f795fbf..fb6e87ce 100644 --- a/test/test_as_container.cpp +++ b/test/test_as_container.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include using doctest::test_suite; diff --git a/test/test_bool_operator.cpp b/test/test_bool_operator.cpp index 93a3be23..aada1500 100644 --- a/test/test_bool_operator.cpp +++ b/test/test_bool_operator.cpp @@ -1,4 +1,9 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif + #include using doctest::test_suite; diff --git a/test/test_compound_arguments.cpp b/test/test_compound_arguments.cpp index 3bc1601e..fc25fdcf 100644 --- a/test/test_compound_arguments.cpp +++ b/test/test_compound_arguments.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include #include diff --git a/test/test_const_correct.cpp b/test/test_const_correct.cpp index 1acfdd40..a139679b 100644 --- a/test/test_const_correct.cpp +++ b/test/test_const_correct.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include using doctest::test_suite; diff --git a/test/test_container_arguments.cpp b/test/test_container_arguments.cpp index 5eab026e..e6596950 100644 --- a/test/test_container_arguments.cpp +++ b/test/test_container_arguments.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include #include diff --git a/test/test_default_args.cpp b/test/test_default_args.cpp index d0cdd253..61fbabc5 100644 --- a/test/test_default_args.cpp +++ b/test/test_default_args.cpp @@ -1,7 +1,13 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include + #include #include +#include using doctest::test_suite; diff --git a/test/test_default_value.cpp b/test/test_default_value.cpp index 15271f96..1a28168d 100644 --- a/test/test_default_value.cpp +++ b/test/test_default_value.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include #include diff --git a/test/test_equals_form.cpp b/test/test_equals_form.cpp index 81c31f83..6d95c3e7 100644 --- a/test/test_equals_form.cpp +++ b/test/test_equals_form.cpp @@ -1,6 +1,14 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include + #include +#include +#include + using doctest::test_suite; TEST_CASE("Basic --value=value" * test_suite("equals_form")) { @@ -36,4 +44,4 @@ TEST_CASE("Basic --value=value with nargs(2)" * test_suite("equals_form")) { parser.parse_args({"test", "--long=value1", "value2"}); REQUIRE((parser.get>("--long") == std::vector{"value1", "value2"})); -} \ No newline at end of file +} diff --git a/test/test_get.cpp b/test/test_get.cpp index ad719b05..d2144a16 100644 --- a/test/test_get.cpp +++ b/test/test_get.cpp @@ -1,6 +1,12 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include +#include + using doctest::test_suite; TEST_CASE("Getting a simple argument" * test_suite("ArgumentParser::get")) { diff --git a/test/test_help.cpp b/test/test_help.cpp index 293daef1..2f29e560 100644 --- a/test/test_help.cpp +++ b/test/test_help.cpp @@ -1,6 +1,12 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include + #include +#include using doctest::test_suite; diff --git a/test/test_invalid_arguments.cpp b/test/test_invalid_arguments.cpp index e8db3f26..86e344cc 100644 --- a/test/test_invalid_arguments.cpp +++ b/test/test_invalid_arguments.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include using doctest::test_suite; diff --git a/test/test_is_used.cpp b/test/test_is_used.cpp index 8d67b851..cfb6e439 100644 --- a/test/test_is_used.cpp +++ b/test/test_is_used.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include using doctest::test_suite; diff --git a/test/test_issue_37.cpp b/test/test_issue_37.cpp index ab9c9840..7e8e2bc1 100644 --- a/test/test_issue_37.cpp +++ b/test/test_issue_37.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include using doctest::test_suite; diff --git a/test/test_negative_numbers.cpp b/test/test_negative_numbers.cpp index fd9b1f9a..f9dd463c 100644 --- a/test/test_negative_numbers.cpp +++ b/test/test_negative_numbers.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include using doctest::test_suite; diff --git a/test/test_optional_arguments.cpp b/test/test_optional_arguments.cpp index dd9cec69..65ea25fe 100644 --- a/test/test_optional_arguments.cpp +++ b/test/test_optional_arguments.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include using doctest::test_suite; diff --git a/test/test_parent_parsers.cpp b/test/test_parent_parsers.cpp index ffb9e005..9f9a7f80 100644 --- a/test/test_parent_parsers.cpp +++ b/test/test_parent_parsers.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include using doctest::test_suite; diff --git a/test/test_parse_args.cpp b/test/test_parse_args.cpp index 7a38abf2..bb3af2a0 100644 --- a/test/test_parse_args.cpp +++ b/test/test_parse_args.cpp @@ -1,6 +1,12 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include +#include + using doctest::test_suite; TEST_CASE("Missing argument" * test_suite("parse_args")) { diff --git a/test/test_parse_known_args.cpp b/test/test_parse_known_args.cpp index 2a9da845..d5a939cb 100644 --- a/test/test_parse_known_args.cpp +++ b/test/test_parse_known_args.cpp @@ -1,6 +1,13 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include +#include +#include + using doctest::test_suite; TEST_CASE("Parse unknown optional and positional arguments without exceptions" * @@ -79,4 +86,4 @@ TEST_CASE("Parse unknown optional and positional arguments in subparsers " REQUIRE((unknown_args == std::vector{"--verbose", "FOO", "5", "BAR", "-jn", "spam"})); } -} \ No newline at end of file +} diff --git a/test/test_positional_arguments.cpp b/test/test_positional_arguments.cpp index cfee4881..16650488 100644 --- a/test/test_positional_arguments.cpp +++ b/test/test_positional_arguments.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include #include diff --git a/test/test_prefix_chars.cpp b/test/test_prefix_chars.cpp index e62b1d9b..eb262738 100644 --- a/test/test_prefix_chars.cpp +++ b/test/test_prefix_chars.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include #include diff --git a/test/test_repr.cpp b/test/test_repr.cpp index c09c3ac5..f7330bcb 100644 --- a/test/test_repr.cpp +++ b/test/test_repr.cpp @@ -1,6 +1,14 @@ +#ifdef WITH_MODULE +import argparse; +import argparse.details; +#else #include +#endif #include + #include +#include +#include using doctest::test_suite; diff --git a/test/test_required_arguments.cpp b/test/test_required_arguments.cpp index 299808aa..7d7a077e 100644 --- a/test/test_required_arguments.cpp +++ b/test/test_required_arguments.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include using doctest::test_suite; diff --git a/test/test_scan.cpp b/test/test_scan.cpp index 6cc53e5c..4210d8f1 100644 --- a/test/test_scan.cpp +++ b/test/test_scan.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include #include diff --git a/test/test_subparsers.cpp b/test/test_subparsers.cpp index 0830ce1e..9e7c29f4 100644 --- a/test/test_subparsers.cpp +++ b/test/test_subparsers.cpp @@ -1,7 +1,14 @@ +#ifdef WITH_MODULE +import argparse; +#else #include -#include +#endif #include +#include +#include +#include + using doctest::test_suite; TEST_CASE("Add subparsers" * test_suite("subparsers")) { @@ -236,4 +243,4 @@ TEST_CASE("Check is_subcommand_used after parse" * test_suite("subparsers")) { REQUIRE(program.is_subcommand_used("clean") == false); REQUIRE(program.is_subcommand_used(command_2) == false); } -} \ No newline at end of file +} diff --git a/test/test_utility.hpp b/test/test_utility.hpp index fd061de7..3a596a5a 100644 --- a/test/test_utility.hpp +++ b/test/test_utility.hpp @@ -1,6 +1,8 @@ #ifndef ARGPARSE_TEST_UTILITY_HPP #define ARGPARSE_TEST_UTILITY_HPP +#include + namespace testutility { // Get value at index from std::list template diff --git a/test/test_value_semantics.cpp b/test/test_value_semantics.cpp index 2cc0f887..03e5db5a 100644 --- a/test/test_value_semantics.cpp +++ b/test/test_value_semantics.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include using doctest::test_suite; diff --git a/test/test_version.cpp b/test/test_version.cpp index 377126e3..3179f566 100644 --- a/test/test_version.cpp +++ b/test/test_version.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include #include diff --git a/xmake.lua b/xmake.lua new file mode 100644 index 00000000..cc33c03a --- /dev/null +++ b/xmake.lua @@ -0,0 +1,89 @@ +set_xmakever("2.8.2") +set_project("argparse") + +set_version("2.9.0", { build = "%Y%m%d%H%M" }) + +option("enable_module") +option("enable_std_import", { defines = "ARGPARSE_MODULE_USE_STD_MODULE" }) +option("enable_tests") +option("enable_samples") + +add_cxxflags( + "-Wall", + "-Wno-long-long", + "-pedantic", + "-Wsign-conversion", + "-Wshadow", + "-Wconversion", + { toolsets = { "clang", "gcc" } } +) +add_cxxflags("cl::/W4") + +if is_plat("windows") then + add_defines("_CRT_SECURE_NO_WARNINGS") +end + +target("argparse", function() + set_languages("c++17") + set_kind("headeronly") + if get_config("enable_module") then + set_languages("c++20") + set_kind("static") -- static atm because of a XMake bug, headeronly doesn't generate package module metadata + end + + add_options("enable_std_import") + + add_includedirs("include", { public = true }) + add_headerfiles("include/argparse/argparse.hpp") + if get_config("enable_module") then + add_files("module/argparse.cppm", { install = true }) + end +end) + +if get_config("enable_tests") then + target("argparse_tests", function() + set_kind("binary") + set_languages("c++17") + set_basename("tests") + + add_includedirs("test") + + add_files("test/main.cpp", { defines = { "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN" } }) + add_files("test/**.cpp") + + add_deps("argparse") + end) + + if get_config("enable_module") then + target("argparse_module_tests", function() + set_kind("binary") + set_languages("c++20") + set_basename("module_tests") + + add_defines("WITH_MODULE") + + add_includedirs("test") + + add_files("test/main.cpp", { defines = { "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN" } }) + add_files("test/**.cpp") + add_files("test/argparse_details.cppm") + + add_deps("argparse") + end) + end +end + +if get_config("enable_samples") then + for _, sample_file in ipairs(os.files("samples/*.cpp")) do + target(path.basename(sample_file), function() + set_kind("binary") + set_languages("c++17") + + add_files(sample_file) + + set_policy("build.c++.modules", false) + + add_deps("argparse") + end) + end +end