Commit Graph

719 Commits

Author SHA1 Message Date
Pranav
5d093dcdc5
Merge pull request #176 from peckato1/master
Add missing <utility> include
2022-05-19 21:17:32 +02:00
Tomáš Pecka
95d4850683 Add missing <utility> include
After upgrading g++ package to 12.1.0 on archlinux I see the following
compilation error:

  /usr/include/argparse/argparse.hpp: In member function ‘void argparse::ArgumentParser::index_argument(list_iterator)’:
  /usr/include/argparse/argparse.hpp:1167:34: error: ‘as_const’ is not a member of ‘std’; did you mean ‘is_const’?
   1167 |     for (const auto &name : std::as_const(it->m_names)) {
        |                                  ^~~~~~~~
        |                                  is_const

It turns out that std::as_const comes from <utility> header [1] which
was not explicitly included.

[1] https://en.cppreference.com/w/cpp/utility/as_const
2022-05-15 16:04:38 +02:00
Pranav
f5ea927f6b
Merge pull request #174 from ericonr/unused2
Fix remaining unused argument warnings.
2022-05-09 13:58:44 -05:00
Érico Nogueira
82eed31d3f Fix remaining unused argument warnings.
Commit 5c5c55b83c missed one such
occurrence.
2022-05-09 14:35:50 -03:00
Pranav
6ba201e210
Merge pull request #172 from skrobinson/fix-minor-cleanups
Fix minor cleanups
2022-04-27 15:12:36 -07:00
Sean Robinson
8b2357475f Add documentation for add_description and add_epilog
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-04-27 08:01:25 -07:00
Sean Robinson
c4faf29feb Replace cend with std::cend
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-04-27 08:00:51 -07:00
Sean Robinson
37a1f3b9e6 Remove unused code in Argument::validate
As far as I can tell, this statement is never true.

When m_values.size() < *expected, ::consume has already thrown "Too few
arguments..." before ::validate is called.

When m_values.size() > *expected, ArgumentParser::parse_args_internal
has already thrown "Maximum number of positional arguments exceeded"
before ::validate is called.

If ::remaining is used to avoid the last exception, this Argument will
always consume the expected number of values, hence this expression is
again false.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-04-27 08:00:17 -07:00
Pranav
b9dd1ef8e3
Merge pull request #162 from skrobinson/wip-port-aayush749-fixes
Port aayush749 fixes
2022-04-25 16:17:16 -07:00
Pranav
e0d656ec71
Merge pull request #171 from Dennis-Bbg/master
Update README.md
2022-04-21 22:51:07 -05:00
Dennis-Bbg
71a9a7a53e
Update README.md
Fixed the example in section" #### Deciding if the value was given by the user".
2022-04-21 11:52:12 +02:00
Pranav Srinivas Kumar
4af831ef72 Bumped library version to v2.4 2022-04-20 08:37:27 -05:00
Pranav
d2acb6aa44
Merge pull request #169 from AmeyaVS/fix/update_doctest
Updates doctest from v2.3.5 to v2.4.8
2022-04-19 14:03:07 -05:00
Pranav
a39f660502
Merge pull request #170 from ericonr/unused
Fix unused argument warnings.
2022-04-19 14:02:50 -05:00
Érico Nogueira
5c5c55b83c Fix unused argument warnings.
Solution suggested by skrobinson. This way, GCC and clang-tidy don't
generate warnings.

Fixes: https://github.com/p-ranav/argparse/issues/167
2022-04-19 13:59:08 -03:00
Ameya Vikram Singh
f56aec307f Updates doctest from v2.3.5 to v2.4.8
Fixes the build error on latest GNU/Linux Systems: (https://github.com/doctest/doctest/issues/473)

Signed-off-by: Ameya Vikram Singh <ameya.v.singh@gmail.com>
2022-04-16 20:35:37 +05:30
Pranav
2312342a62
Merge pull request #166 from ericonr/fix-version
Fix regression in version printing.
2022-04-14 10:48:31 -05:00
Érico Nogueira
3b89546fd0 Fix regression in version printing.
This regression was caused by commit
ea1f7ef663, which didn't add "\n" to the
version printing statement. We use std::endl now for compatibility
across platforms.
2022-04-13 10:29:37 -03:00
Pranav Srinivas Kumar
1a552dfd60 Bumped library version to v2.3 2022-04-01 19:05:46 -05:00
Pranav
7f11534e39
Merge pull request #163 from skrobinson/wip-disable-sa
Remove StaticAnalysis Action
2022-03-28 18:00:27 -05:00
Sean Robinson
eaa8214962 Remove StaticAnalysis Action
I am seeing too many errors due to bad tool configuration, not from
problems in project code.  So, disable SA until I can make it work more
reliably.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-03-28 13:03:05 -07:00
Sean Robinson
67d2e4476f Annotate range-for loops' structured bindings as [[maybe_unused]]
The 'unused' variable in both cases is most-definitely unused in the loop.
This is a cppcheck warning that appeared after moving these two loops to
range-for.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-03-24 14:21:14 -07:00
Sean Robinson
843e4eefb0 Move ArgumentParser::parse_args_validate logic into ::parse_args
This code was previously moved from ::parse_args to its own method, but
has since been simplified.  Moving the actual work to Argument::validate
in commit 603e87ae6 leaves a single loop that fits back into ::parse_args.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-03-24 14:19:20 -07:00
Sean Robinson
063d708c3e Modify ArgumentParser::get_length_of_longest_argument method run in O(1) space
Closes #124

Reported-by: Aayush Anand <aaayushanand5@gmail.com>
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-03-23 15:02:42 -07:00
Aayush Anand
0d868fdca8 Modify ArgumentParser::parse_args_validate() method to use a for loop instead of std::for_each()
Suggested-by: Aayush Anand <aaayushanand5@gmail.com>
[skrobinson: Updated for latest formatting and naming conventions]
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-03-23 15:02:42 -07:00
Pranav
cba0a1b3c7
Merge pull request #160 from skrobinson/wip-tidy
Enable clang-tidy readability-braces-around-statements check
2022-03-23 16:55:52 -05:00
Pranav
c20621489d
Merge pull request #157 from Sam4uk/cmake_edit
edit CMakeLists.txt
2022-02-23 21:21:45 +05:30
Sean Robinson
ce3c43eb9b Rename identifiers
There are no functional changes in this commit.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-02-10 09:41:20 -07:00
Sean Robinson
985ea8666d Update identifier names for structs
The new naming pattern is CamelCase for structs, except parse_number as a
primarily callable interface.  Trait structs are named Has*Traits
and constexpr variables to the struct template are named Is*.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-02-09 15:53:08 -07:00
Sean Robinson
c50346c1df Remove is_representable_v trait
This trait is unused and removing it does not cause any tests to fail.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-02-09 15:53:08 -07:00
Sean Robinson
cb2777db6e Update header source format with clang-format
Most changes are to better fit within "ColumnLimit: 80".

The change from "T &&... var" to "T &&...var" is caused by
"PointerAlignment: Right".

Member functions chained from add_argument() use ContinuationIndentWidth,
which is set to 4.  Setting ContinuationIndentWidth to 2 causes many
other continuation lines to change.  So, this commit uses the original
value (i.e. 4) as the preferred size.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-02-09 15:53:08 -07:00
Sean Robinson
486bfdaf8d Update clang-format configuration standard to C++17
The "Cpp11" alias is deprecated for Latest (a rolling standard).  For now,
stick to C++17.

Includes end-of-line whitespace removal.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-02-09 15:53:08 -07:00
Sean Robinson
a915728da0 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>
2022-02-09 15:53:08 -07:00
Sean Robinson
6564839971 Enable clang-tidy readability-function-cognitive-complexity check
The two functions previously flagged by this check,
Argument::is_decimal_literal and Argument::validate, fell below the
default Cognitive Complexity threshold as a result of the branch
simplification for the readability-else-after-return check.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-02-09 15:53:08 -07:00
Sean Robinson
d0a492ccba Enable clang-tidy readability-else-after-return check
A common pattern in the previous code was goto/return/throw if a condition
is true, else goto/return/throw something different.  The new pattern
uses the fact that the second goto/return/throw is only reachable when the
first goto/return/throw is not called.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-02-09 15:53:08 -07:00
Sean Robinson
3c317ddd2d Enable clang-tidy clang-analyzer default checks
Surprisingly, no fixes are required in argparse when turning on this suite
of checks.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-02-09 15:53:08 -07:00
Sean Robinson
0b74da54d4 Enable clang-tidy cppcoreguidelines-special-member-functions check
Also adds a default destructor, as recommended by the check.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-02-09 15:53:08 -07:00
Sean Robinson
c25a959597 Enable clang-tidy readability-static-accessed-through-instance check
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-02-09 15:53:08 -07:00
Sean Robinson
bd4837f240 Enable clang-tidy's readability-qualified-auto check
Following the clang-tidy suggested fix in consume_digits causes compile
failures with MSVC 19.29 in our CI.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-02-09 15:27:16 -07:00
Sean Robinson
b5fb663bc8 Enable clang-tidy readability-named-parameter check
Adds names recommended by clang-tidy (e.g. "unused").

Note that clang-tidy v12 appears to detect unnamed parameters in lambdas,
while clang-tidy v13 does not.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-02-09 14:05:21 -07:00
Sean Robinson
9eb1fe5cef Enable clang-tidy readability-magic-numbers check
Adds names for integer bases used with details::parse_number.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-02-07 14:29:25 -07:00
Sean Robinson
b918763adf Enable clang-tidy readability-implicit-bool-conversion check
Enabling this check caught the implicit bool conversion with
default_arguments::operator& fixed in the previous commit.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-02-07 14:27:06 -07:00
Sean Robinson
7cbc66f65b Return default_arguments from operator& of two default_arguments
operator& should return combined values of the same type, not a new type
(i.e. bool).  This is much more verbose, but easier to reason about
without implied conversion.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-02-07 14:27:06 -07:00
Sean Robinson
6a8b1318ec Enable clang-tidy readability-container-size-empty check
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-02-07 14:27:06 -07:00
Sean Robinson
158b8a0d2f Enable clang-tidy readability-braces-around-statements check
All tests still pass.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-02-07 13:10:03 -07:00
Sam4uk
06f687b594
update cmake_minimum_required to 3.12.4 2022-02-07 22:09:36 +02:00
Pranav
419648bf74
Merge pull request #158 from skrobinson/fix-SA-runner
Refactor configuration for StaticAnalysis
2022-02-07 13:04:53 -06:00
Sean Robinson
97204363b5 Refactor configuration for StaticAnalysis
Upstream StaticAnalysis looks to be changing for more flexibility with
source files to process.  While these changes may eventually benefit
argparse, the public interfaces are in flux and we need a stable tool.
argparse also needs a SA change which is not yet upstream.

Trying to run clang-tidy via StaticAnalysis on a single file in a
directory with many source file is not easy, so move the analysis kernel
to a location (i.e. tools) where it is the only C++ source file.

Another benefit is cppcheck no longer needs to be told to ignore the test
sources.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-02-07 11:51:22 -07:00
Sam4uk
5a1b4c3068 edit CMakeLists.txt 2022-02-04 23:36:26 +02:00
Pranav
79df7808d2
Merge pull request #155 from skrobinson/fix-test-server-deprecation
Remove Windows Server 2016 from test matrix
2022-01-11 09:40:13 -06:00