mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-04 15:14:39 +00:00
Merge pull request #202 from p-ranav/bugfix/94_implicit_conversions
Closes #94
This commit is contained in:
commit
d512563c45
@ -98,8 +98,10 @@ template <typename T> std::string repr(T const &val) {
|
||||
out << repr(*val.begin());
|
||||
std::for_each(
|
||||
std::next(val.begin()),
|
||||
std::next(val.begin(),
|
||||
std::min<std::size_t>(size, repr_max_container_size) - 1),
|
||||
std::next(
|
||||
val.begin(),
|
||||
static_cast<typename T::iterator::difference_type>(
|
||||
std::min<std::size_t>(size, repr_max_container_size) - 1)),
|
||||
[&out](const auto &v) { out << " " << repr(v); });
|
||||
if (size <= repr_max_container_size) {
|
||||
out << " ";
|
||||
@ -507,7 +509,8 @@ public:
|
||||
if ((dist = static_cast<std::size_t>(std::distance(start, end))) >=
|
||||
num_args_min) {
|
||||
if (num_args_max < dist) {
|
||||
end = std::next(start, num_args_max);
|
||||
end = std::next(start, static_cast<typename Iterator::difference_type>(
|
||||
num_args_max));
|
||||
}
|
||||
if (!m_accepts_optional_like_value) {
|
||||
end = std::find_if(start, end, Argument::is_optional);
|
||||
@ -526,7 +529,8 @@ public:
|
||||
std::for_each(first, last, f);
|
||||
if (!self.m_default_value.has_value()) {
|
||||
if (!self.m_accepts_optional_like_value) {
|
||||
self.m_values.resize(std::distance(first, last));
|
||||
self.m_values.resize(
|
||||
static_cast<std::size_t>(std::distance(first, last)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -729,7 +733,7 @@ private:
|
||||
auto consume_digits = [=](std::string_view s) {
|
||||
// NOLINTNEXTLINE(readability-qualified-auto)
|
||||
auto it = std::find_if_not(std::begin(s), std::end(s), is_digit);
|
||||
return s.substr(it - std::begin(s));
|
||||
return s.substr(static_cast<std::size_t>(it - std::begin(s)));
|
||||
};
|
||||
|
||||
switch (lookahead(s)) {
|
||||
@ -1165,7 +1169,7 @@ public:
|
||||
}
|
||||
|
||||
for (const auto &argument : parser.m_positional_arguments) {
|
||||
stream.width(longest_arg_length);
|
||||
stream.width(static_cast<std::streamsize>(longest_arg_length));
|
||||
stream << argument;
|
||||
}
|
||||
|
||||
@ -1175,7 +1179,7 @@ public:
|
||||
}
|
||||
|
||||
for (const auto &argument : parser.m_optional_arguments) {
|
||||
stream.width(longest_arg_length);
|
||||
stream.width(static_cast<std::streamsize>(longest_arg_length));
|
||||
stream << argument;
|
||||
}
|
||||
|
||||
@ -1185,7 +1189,7 @@ public:
|
||||
: "\n")
|
||||
<< "Subcommands:\n";
|
||||
for (const auto &[command, subparser] : parser.m_subparser_map) {
|
||||
stream.width(longest_arg_length);
|
||||
stream.width(static_cast<std::streamsize>(longest_arg_length));
|
||||
stream << command << "\t" << subparser->get().m_description << "\n";
|
||||
}
|
||||
}
|
||||
|
BIN
include/argparse/test
Executable file
BIN
include/argparse/test
Executable file
Binary file not shown.
15
include/argparse/test.cpp
Normal file
15
include/argparse/test.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include "argparse.hpp"
|
||||
#include <cassert>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
argparse::ArgumentParser program("test");
|
||||
program.add_argument("--foo").implicit_value(true).default_value(false);
|
||||
program.add_argument("bar");
|
||||
|
||||
auto unknown_args =
|
||||
program.parse_known_args({"test", "--foo", "--badger", "BAR", "spam"});
|
||||
|
||||
assert(program.get<bool>("--foo") == true);
|
||||
assert(program.get<std::string>("bar") == std::string{"BAR"});
|
||||
assert((unknown_args == std::vector<std::string>{"--badger", "spam"}));
|
||||
}
|
@ -10,7 +10,7 @@ if(MSVC)
|
||||
endif()
|
||||
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
|
||||
# Update if necessary
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic -Wsign-conversion")
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
|
Loading…
Reference in New Issue
Block a user