From 2460019e2e190f5c0d9abefa8124d53cf34c7e37 Mon Sep 17 00:00:00 2001 From: Sean Robinson Date: Wed, 22 Jun 2022 14:02:00 -0700 Subject: [PATCH 1/2] Update copyright date Signed-off-by: Sean Robinson --- include/argparse/argparse.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/argparse/argparse.hpp b/include/argparse/argparse.hpp index c9a256e..299fca0 100644 --- a/include/argparse/argparse.hpp +++ b/include/argparse/argparse.hpp @@ -7,7 +7,7 @@ Licensed under the MIT License . SPDX-License-Identifier: MIT -Copyright (c) 2019-2021 Pranav Srinivas Kumar +Copyright (c) 2019-2022 Pranav Srinivas Kumar and other contributors. Permission is hereby granted, free of charge, to any person obtaining a copy From 14097df904a992ed9932c89010c30dbc5592bfb1 Mon Sep 17 00:00:00 2001 From: Sean Robinson Date: Wed, 6 Jul 2022 09:59:58 -0700 Subject: [PATCH 2/2] Clean miscellaneous source styling 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 --- CONTRIBUTING.md | 10 ++++++++++ include/argparse/argparse.hpp | 28 +++++++++++++++++----------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bd89b75..9d9678b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 +``` diff --git a/include/argparse/argparse.hpp b/include/argparse/argparse.hpp index 299fca0..5d9fa4e 100644 --- a/include/argparse/argparse.hpp +++ b/include/argparse/argparse.hpp @@ -505,7 +505,8 @@ public: m_values.emplace_back(m_implicit_value); std::visit([](const auto &f) { f({}); }, m_action); return start; - } else if ((dist = static_cast(std::distance(start, end))) >= num_args_min) { + } + if ((dist = static_cast(std::distance(start, end))) >= num_args_min) { if (num_args_max < dist) { end = std::next(start, num_args_max); } @@ -525,8 +526,9 @@ public: 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)); + } } } @@ -619,9 +621,11 @@ private: 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 { @@ -647,8 +651,9 @@ private: 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()) { @@ -656,8 +661,7 @@ private: } 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()); } @@ -862,11 +866,13 @@ private: } if (m_default_value.has_value()) { return std::any_cast(m_default_value); - } else { - if constexpr (details::IsContainer) - if (!m_accepts_optional_like_value) - return any_cast_container(m_values); } + if constexpr (details::IsContainer) { + if (!m_accepts_optional_like_value) { + return any_cast_container(m_values); + } + } + throw std::logic_error("No value provided for '" + m_names.back() + "'."); }