mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-03 22:54:39 +00:00
Enable clang-tidy cppcoreguidelines-avoid-c-arrays check
Also converts most C-style arrays to a std::array onjects. The check is disabled for ArgumentParser::parse_args(int, const char *const[]) as this is a helper function to convert away from a common input format. Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
This commit is contained in:
parent
6564839971
commit
a915728da0
@ -1,6 +1,7 @@
|
|||||||
Checks:
|
Checks:
|
||||||
-*,
|
-*,
|
||||||
clang-analyzer-*,
|
clang-analyzer-*,
|
||||||
|
cppcoreguidelines-avoid-c-arrays,
|
||||||
cppcoreguidelines-special-member-functions,
|
cppcoreguidelines-special-member-functions,
|
||||||
readability-*,
|
readability-*,
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ SOFTWARE.
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <any>
|
#include <any>
|
||||||
|
#include <array>
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <charconv>
|
#include <charconv>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@ -350,7 +351,8 @@ class Argument {
|
|||||||
-> std::ostream &;
|
-> std::ostream &;
|
||||||
|
|
||||||
template <std::size_t N, std::size_t... I>
|
template <std::size_t N, std::size_t... I>
|
||||||
explicit Argument(std::string_view(&&a)[N], std::index_sequence<I...> unused)
|
explicit Argument(std::array<std::string_view, N> &&a,
|
||||||
|
std::index_sequence<I...> unused)
|
||||||
: mIsOptional((is_optional(a[I]) || ...)), mIsRequired(false),
|
: mIsOptional((is_optional(a[I]) || ...)), mIsRequired(false),
|
||||||
mIsRepeatable(false), mIsUsed(false) {
|
mIsRepeatable(false), mIsUsed(false) {
|
||||||
((void)mNames.emplace_back(a[I]), ...);
|
((void)mNames.emplace_back(a[I]), ...);
|
||||||
@ -362,7 +364,7 @@ class Argument {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
template <std::size_t N>
|
template <std::size_t N>
|
||||||
explicit Argument(std::string_view(&&a)[N])
|
explicit Argument(std::array<std::string_view, N> &&a)
|
||||||
: Argument(std::move(a), std::make_index_sequence<N>{}) {}
|
: Argument(std::move(a), std::make_index_sequence<N>{}) {}
|
||||||
|
|
||||||
Argument &help(std::string aHelp) {
|
Argument &help(std::string aHelp) {
|
||||||
@ -910,7 +912,7 @@ public:
|
|||||||
// Parameter packing
|
// Parameter packing
|
||||||
// Call add_argument with variadic number of string arguments
|
// Call add_argument with variadic number of string arguments
|
||||||
template <typename... Targs> Argument &add_argument(Targs... Fargs) {
|
template <typename... Targs> Argument &add_argument(Targs... Fargs) {
|
||||||
using array_of_sv = std::string_view[sizeof...(Targs)];
|
using array_of_sv = std::array<std::string_view, sizeof...(Targs)>;
|
||||||
auto tArgument = mOptionalArguments.emplace(cend(mOptionalArguments),
|
auto tArgument = mOptionalArguments.emplace(cend(mOptionalArguments),
|
||||||
array_of_sv{Fargs...});
|
array_of_sv{Fargs...});
|
||||||
|
|
||||||
@ -966,6 +968,7 @@ public:
|
|||||||
* ArgumentParser
|
* ArgumentParser
|
||||||
* @throws std::runtime_error in case of any invalid argument
|
* @throws std::runtime_error in case of any invalid argument
|
||||||
*/
|
*/
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays)
|
||||||
void parse_args(int argc, const char *const argv[]) {
|
void parse_args(int argc, const char *const argv[]) {
|
||||||
std::vector<std::string> arguments;
|
std::vector<std::string> arguments;
|
||||||
std::copy(argv, argv + argc, std::back_inserter(arguments));
|
std::copy(argv, argv + argc, std::back_inserter(arguments));
|
||||||
|
Loading…
Reference in New Issue
Block a user