Skip to content

Commit

Permalink
Clean miscellaneous source styling
Browse files Browse the repository at this point in the history
Clears warnings for the following checks in clang-tidy:
  readability-braces-around-statements
  readability-else-after-return checks

Also adds hints about code style to CONTRIBUTING document.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
  • Loading branch information
skrobinson committed Jul 6, 2022
1 parent 2460019 commit 14097df
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

[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
```
28 changes: 17 additions & 11 deletions include/argparse/argparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,8 @@ class Argument {
m_values.emplace_back(m_implicit_value);
std::visit([](const auto &f) { f({}); }, m_action);
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) {
end = std::next(start, num_args_max);
}
Expand All @@ -525,8 +526,9 @@ class Argument {
void operator()(void_action &f) {
std::for_each(first, last, f);
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));
}
}
}

Expand Down Expand Up @@ -619,9 +621,11 @@ class Argument {
std::size_t m_max;

public:
NArgsRange(std::size_t minimum, std::size_t maximum) : m_min(minimum), m_max(maximum) {
if (minimum > maximum)
NArgsRange(std::size_t minimum, std::size_t maximum)
: m_min(minimum), m_max(maximum) {
if (minimum > maximum) {
throw std::logic_error("Range of number of arguments is invalid");
}
}

bool contains(std::size_t value) const {
Expand All @@ -647,17 +651,17 @@ class Argument {

void throw_nargs_range_validation_error() const {
std::stringstream stream;
if (!m_used_name.empty())
if (!m_used_name.empty()) {
stream << m_used_name << ": ";
}
if (m_num_args_range.is_exact()) {
stream << m_num_args_range.get_min();
} else if (m_num_args_range.is_right_bounded()) {
stream << m_num_args_range.get_min() << " to " << m_num_args_range.get_max();
} else {
stream << m_num_args_range.get_min() << " or more";
}
stream << " argument(s) expected. "
<< m_values.size() << " provided.";
stream << " argument(s) expected. " << m_values.size() << " provided.";
throw std::runtime_error(stream.str());
}

Expand Down Expand Up @@ -862,11 +866,13 @@ class Argument {
}
if (m_default_value.has_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() + "'.");
}

Expand Down

0 comments on commit 14097df

Please sign in to comment.