Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add C++20 module #290

Merged
merged 10 commits into from
Oct 20, 2023
1 change: 1 addition & 0 deletions .stylua.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
indent_type = "Spaces"
7 changes: 5 additions & 2 deletions include/argparse/argparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <algorithm>
#include <any>
#include <array>
Expand All @@ -53,6 +55,7 @@ SOFTWARE.
#include <utility>
#include <variant>
#include <vector>
#endif

namespace argparse {

Expand All @@ -72,7 +75,7 @@ struct HasContainerTraits<
decltype(std::declval<T>().size())>> : std::true_type {};

template <typename T>
static constexpr bool IsContainer = HasContainerTraits<T>::value;
inline constexpr bool IsContainer = HasContainerTraits<T>::value;
Arthapz marked this conversation as resolved.
Show resolved Hide resolved

template <typename T, typename = void>
struct HasStreamableTraits : std::false_type {};
Expand All @@ -84,7 +87,7 @@ struct HasStreamableTraits<
: std::true_type {};

template <typename T>
static constexpr bool IsStreamable = HasStreamableTraits<T>::value;
inline constexpr bool IsStreamable = HasStreamableTraits<T>::value;
Arthapz marked this conversation as resolved.
Show resolved Hide resolved

constexpr std::size_t repr_max_container_size = 5;

Expand Down
49 changes: 49 additions & 0 deletions module/argparse.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
__ _ _ __ __ _ _ __ __ _ _ __ ___ ___
/ _` | '__/ _` | '_ \ / _` | '__/ __|/ _ \ Argument Parser for Modern C++
| (_| | | | (_| | |_) | (_| | | \__ \ __/ https://github.com/p-ranav/argparse
\__,_|_| \__, | .__/ \__,_|_| |___/\___|
|___/|_|

Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2019-2022 Pranav Srinivas Kumar <[email protected]>
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;

#include <argparse/argparse.hpp>

export module argparse;

#ifdef ARGPARSE_MODULE_USE_STD_MODULE
import std;
#endif

export namespace argparse {
using argparse::nargs_pattern;
using argparse::default_arguments;
using argparse::operator&;
using argparse::Argument;
using argparse::ArgumentParser;
}

10 changes: 10 additions & 0 deletions test/argparse_details.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module;

#include <argparse/argparse.hpp>

export module argparse.details;

export namespace argparse::details {
using argparse::details::repr;
}

4 changes: 4 additions & 0 deletions test/test_actions.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>

using doctest::test_suite;
Expand Down
7 changes: 7 additions & 0 deletions test/test_append.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>

#include <vector>
#include <string>

using doctest::test_suite;

TEST_CASE("Simplest .append" * test_suite("append")) {
Expand Down
4 changes: 4 additions & 0 deletions test/test_as_container.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>

using doctest::test_suite;
Expand Down
5 changes: 5 additions & 0 deletions test/test_bool_operator.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif

#include <doctest.hpp>

using doctest::test_suite;
Expand Down
4 changes: 4 additions & 0 deletions test/test_compound_arguments.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>
#include <test_utility.hpp>

Expand Down
4 changes: 4 additions & 0 deletions test/test_const_correct.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>

using doctest::test_suite;
Expand Down
4 changes: 4 additions & 0 deletions test/test_container_arguments.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>
#include <test_utility.hpp>

Expand Down
6 changes: 6 additions & 0 deletions test/test_default_args.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>

#include <sstream>
#include <streambuf>
#include <iostream>

using doctest::test_suite;

Expand Down
4 changes: 4 additions & 0 deletions test/test_default_value.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>
#include <string>

Expand Down
10 changes: 9 additions & 1 deletion test/test_equals_form.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>

#include <iostream>
#include <vector>
#include <string>

using doctest::test_suite;

TEST_CASE("Basic --value=value" * test_suite("equals_form")) {
Expand Down Expand Up @@ -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<std::vector<std::string>>("--long") ==
std::vector<std::string>{"value1", "value2"}));
}
}
6 changes: 6 additions & 0 deletions test/test_get.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>

#include <any>

using doctest::test_suite;

TEST_CASE("Getting a simple argument" * test_suite("ArgumentParser::get")) {
Expand Down
6 changes: 6 additions & 0 deletions test/test_help.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>

#include <sstream>
#include <optional>

using doctest::test_suite;

Expand Down
4 changes: 4 additions & 0 deletions test/test_invalid_arguments.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>

using doctest::test_suite;
Expand Down
4 changes: 4 additions & 0 deletions test/test_is_used.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>

using doctest::test_suite;
Expand Down
4 changes: 4 additions & 0 deletions test/test_issue_37.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>

using doctest::test_suite;
Expand Down
4 changes: 4 additions & 0 deletions test/test_negative_numbers.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>

using doctest::test_suite;
Expand Down
4 changes: 4 additions & 0 deletions test/test_optional_arguments.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>

using doctest::test_suite;
Expand Down
4 changes: 4 additions & 0 deletions test/test_parent_parsers.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>

using doctest::test_suite;
Expand Down
6 changes: 6 additions & 0 deletions test/test_parse_args.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>

#include <optional>

using doctest::test_suite;

TEST_CASE("Missing argument" * test_suite("parse_args")) {
Expand Down
9 changes: 8 additions & 1 deletion test/test_parse_known_args.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>

#include <vector>
#include <string>

using doctest::test_suite;

TEST_CASE("Parse unknown optional and positional arguments without exceptions" *
Expand Down Expand Up @@ -79,4 +86,4 @@ TEST_CASE("Parse unknown optional and positional arguments in subparsers "
REQUIRE((unknown_args == std::vector<std::string>{"--verbose", "FOO", "5",
"BAR", "-jn", "spam"}));
}
}
}
4 changes: 4 additions & 0 deletions test/test_positional_arguments.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <cmath>
#include <doctest.hpp>

Expand Down
4 changes: 4 additions & 0 deletions test/test_prefix_chars.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <cmath>
#include <doctest.hpp>

Expand Down
8 changes: 8 additions & 0 deletions test/test_repr.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#ifdef WITH_MODULE
import argparse;
import argparse.details;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>

#include <set>
#include <list>
#include <sstream>

using doctest::test_suite;

Expand Down
4 changes: 4 additions & 0 deletions test/test_required_arguments.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>

using doctest::test_suite;
Expand Down
4 changes: 4 additions & 0 deletions test/test_scan.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>
#include <stdint.h>

Expand Down
11 changes: 9 additions & 2 deletions test/test_subparsers.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#include <cmath>
#endif
#include <doctest.hpp>

#include <cmath>
#include <vector>
#include <string>

using doctest::test_suite;

TEST_CASE("Add subparsers" * test_suite("subparsers")) {
Expand Down Expand Up @@ -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);
}
}
}
Loading
Loading