mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-03 22:54:39 +00:00
Merge pull request #182 from skrobinson/wip-post-2.6-cleanups
Post-2.6 cleanups
This commit is contained in:
commit
4801fd0bdc
@ -5,3 +5,13 @@ Contributions are welcomed. Open a pull-request or an issue.
|
|||||||
This project adheres to the [Open Code of Conduct][code-of-conduct]. By participating, you are expected to honor this code.
|
This project adheres to the [Open Code of Conduct][code-of-conduct]. By participating, you are expected to honor this code.
|
||||||
|
|
||||||
[code-of-conduct]: https://github.com/spotify/code-of-conduct/blob/master/code-of-conduct.md
|
[code-of-conduct]: https://github.com/spotify/code-of-conduct/blob/master/code-of-conduct.md
|
||||||
|
|
||||||
|
## Code Style
|
||||||
|
|
||||||
|
This project prefers, but does not strictly enforce, a specific source code style. The style is described in `.clang-format` and `.clang-tidy`.
|
||||||
|
|
||||||
|
To generate a clang-tidy report:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
clang-tidy --extra-arg=-std=c++17 --config-file=.clang-tidy include/argparse/argparse.hpp
|
||||||
|
```
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||||
SPDX-License-Identifier: MIT
|
SPDX-License-Identifier: MIT
|
||||||
Copyright (c) 2019-2021 Pranav Srinivas Kumar <pranav.srinivas.kumar@gmail.com>
|
Copyright (c) 2019-2022 Pranav Srinivas Kumar <pranav.srinivas.kumar@gmail.com>
|
||||||
and other contributors.
|
and other contributors.
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
@ -505,7 +505,8 @@ public:
|
|||||||
m_values.emplace_back(m_implicit_value);
|
m_values.emplace_back(m_implicit_value);
|
||||||
std::visit([](const auto &f) { f({}); }, m_action);
|
std::visit([](const auto &f) { f({}); }, m_action);
|
||||||
return start;
|
return start;
|
||||||
} else if ((dist = static_cast<std::size_t>(std::distance(start, end))) >= num_args_min) {
|
}
|
||||||
|
if ((dist = static_cast<std::size_t>(std::distance(start, end))) >= num_args_min) {
|
||||||
if (num_args_max < dist) {
|
if (num_args_max < dist) {
|
||||||
end = std::next(start, num_args_max);
|
end = std::next(start, num_args_max);
|
||||||
}
|
}
|
||||||
@ -525,8 +526,9 @@ public:
|
|||||||
void operator()(void_action &f) {
|
void operator()(void_action &f) {
|
||||||
std::for_each(first, last, f);
|
std::for_each(first, last, f);
|
||||||
if (!self.m_default_value.has_value()) {
|
if (!self.m_default_value.has_value()) {
|
||||||
if (!self.m_accepts_optional_like_value)
|
if (!self.m_accepts_optional_like_value) {
|
||||||
self.m_values.resize(std::distance(first, last));
|
self.m_values.resize(std::distance(first, last));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -619,9 +621,11 @@ private:
|
|||||||
std::size_t m_max;
|
std::size_t m_max;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NArgsRange(std::size_t minimum, std::size_t maximum) : m_min(minimum), m_max(maximum) {
|
NArgsRange(std::size_t minimum, std::size_t maximum)
|
||||||
if (minimum > maximum)
|
: m_min(minimum), m_max(maximum) {
|
||||||
|
if (minimum > maximum) {
|
||||||
throw std::logic_error("Range of number of arguments is invalid");
|
throw std::logic_error("Range of number of arguments is invalid");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool contains(std::size_t value) const {
|
bool contains(std::size_t value) const {
|
||||||
@ -647,8 +651,9 @@ private:
|
|||||||
|
|
||||||
void throw_nargs_range_validation_error() const {
|
void throw_nargs_range_validation_error() const {
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
if (!m_used_name.empty())
|
if (!m_used_name.empty()) {
|
||||||
stream << m_used_name << ": ";
|
stream << m_used_name << ": ";
|
||||||
|
}
|
||||||
if (m_num_args_range.is_exact()) {
|
if (m_num_args_range.is_exact()) {
|
||||||
stream << m_num_args_range.get_min();
|
stream << m_num_args_range.get_min();
|
||||||
} else if (m_num_args_range.is_right_bounded()) {
|
} else if (m_num_args_range.is_right_bounded()) {
|
||||||
@ -656,8 +661,7 @@ private:
|
|||||||
} else {
|
} else {
|
||||||
stream << m_num_args_range.get_min() << " or more";
|
stream << m_num_args_range.get_min() << " or more";
|
||||||
}
|
}
|
||||||
stream << " argument(s) expected. "
|
stream << " argument(s) expected. " << m_values.size() << " provided.";
|
||||||
<< m_values.size() << " provided.";
|
|
||||||
throw std::runtime_error(stream.str());
|
throw std::runtime_error(stream.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -862,11 +866,13 @@ private:
|
|||||||
}
|
}
|
||||||
if (m_default_value.has_value()) {
|
if (m_default_value.has_value()) {
|
||||||
return std::any_cast<T>(m_default_value);
|
return std::any_cast<T>(m_default_value);
|
||||||
} else {
|
|
||||||
if constexpr (details::IsContainer<T>)
|
|
||||||
if (!m_accepts_optional_like_value)
|
|
||||||
return any_cast_container<T>(m_values);
|
|
||||||
}
|
}
|
||||||
|
if constexpr (details::IsContainer<T>) {
|
||||||
|
if (!m_accepts_optional_like_value) {
|
||||||
|
return any_cast_container<T>(m_values);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
throw std::logic_error("No value provided for '" + m_names.back() + "'.");
|
throw std::logic_error("No value provided for '" + m_names.back() + "'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user