Commit Graph

485 Commits

Author SHA1 Message Date
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
Sean Robinson
736099ef3f Remove Windows Server 2016 from test matrix
The Windows Server 2016 test environment is scheduled for removal on
March 15, 2022.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-01-11 08:33:41 -07:00
Pranav
fcfbe7141e
Merge pull request #148 from skrobinson/feat-add-sa-pr-action
Add StaticAnalysis PR Action
2022-01-11 09:11:10 -06:00
Sean Robinson
6246a9df0e Change Static Analysis trigger event to pull_request_target
The GH security model restricts comment posting from PR actions.
StaticAnalysis has added support for pull_request_target to mitigate
risks while still allowing comments by the bot.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-01-11 06:48:00 -07:00
Sean Robinson
c0bbcf613c Remove sentry check in ArgumentParser::operator<<
cppcheck reports "Variable 'sen' is assigned a value that is never used.
[unreadVariable]" for this line.

As far as I understand, std::ostream::sentry is used to prepare access to
the stream buffer.  But, we are never directly accessing the stream
buffer.  Stream access in this function uses other operator<< functions.

Most noise in this patch is about unindenting after if() removal.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-11-10 13:54:35 -07:00
Sean Robinson
abb2206141 Declare lambda parameter and ArgumentParser::print_help as const
These were respectively reported as constParameter and functionConst
style issues by cppcheck.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-11-10 13:54:33 -07:00
Sean Robinson
6530a06747 Copy more members in ArgumentParser copy constructor
This showed as a cppcheck warning: uninitMemberVar.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-11-10 13:54:31 -07:00
Sean Robinson
8d8282bac3 Add Static Analysis action to run on Pull Request
Unit test source files are not currently checked.  Hopefully, these can
be added so that all source files in a pull request are verified.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-11-10 13:54:29 -07:00
Sean Robinson
9a9c3042aa Add a clang-tidy configuration file
This file matches the current practices of the argparse project.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-11-10 13:54:27 -07:00
Sean Robinson
18a229e849 Add a minimal binary to generate compile_commands.json file
clang-tidy needs compile_commands.json to generate a set of source files
to parse.  tidy-base is not built but is used as a source file in which
included headers can be parsed.  Without this process, clang-tidy will
process many other source files (e.g. doctest.hpp) that we do not want
to worry about.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-11-10 13:54:25 -07:00
Pranav
4cacdc4b30
Merge pull request #147 from MaciejPatro/master
Improve thrown message in case of invalid argument.
2021-11-09 12:44:40 -06:00
Maciej Patro
87afaba6ba Improve thrown message in case of invalid argument.
Now message contains information which argument is the source of error.
It's easier to spot typo/understand which part of more complex command
is the source of problem.
2021-11-05 09:56:17 +01:00
Pranav
b9583b42ab
Merge pull request #146 from p-ranav/update_readme_stdout_to_stderr
Update readme stdout to stderr
2021-11-03 08:34:40 -05:00
Pranav Srinivas Kumar
6f1a90f101 Removed duplicate entry for Daniel Marshall 2021-11-03 08:31:09 -05:00
Ashwin Rohit
2e25423db8 Modify README.md to show printing errors to stderr instead of stdout 2021-11-03 08:29:56 -05:00
Pranav
9c729f54b1
Updated contributors 2021-10-31 17:34:51 -05:00
Pranav
10190c89dc
Merge pull request #144 from aashwinr/update_err
Modify README.md to show printing errors to stderr instead of stdout
2021-10-31 17:22:32 -05:00
Ashwin Rohit
2c55a2e423 Modify README.md to show printing errors to stderr instead of stdout 2021-10-31 12:29:19 -07:00
Pranav
b98bf25a34
Merge pull request #142 from skrobinson/wip-deactivatable-defaults
Actions with nonary arguments, removable defaults, and some clean ups
2021-10-27 12:52:29 -05:00
Sean Robinson
5cceb98e3c Update "Printing Help" documentation
Help output has changed format over time.  This updates the README
example to reflect current practice by running the example code
and copy-pasting its output.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-10-27 09:02:33 -07:00
Sean Robinson
ea1f7ef663 Allow removal of default arguments (i.e. --help and --version)
The help and version arguments are still included by default, but which
default arguments to include can be overridden at ArgumentParser creation.

argparse generally copies Python argparse behavior.  This includes a
default `--help`/`-h` argument to print a help message and exit.  Some
developers using argparse find the automatic exit to be undesirable.

The Python argparse has an opt-out parameter when constructing an
ArgumentParser.  Using `add_help=False` avoids adding a default `--help`
argument and allows the developer to implement a custom help.

This commit adds a similar opt-out to our C++ argparse, but keeps the
current behavior as the default.  The `--help`/`-h` and `--version`/`-v`
Arguments handle their own output and exit rather than specially treating
them in ArgumentParser::parse_args_internal.

Closes #119
Closes #138
Closes #139

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-10-27 09:02:33 -07:00
Sean Robinson
2b05334a3c Run Argumnet::action functor for zero-parameter arguments
Previously, only arguments with one or more parameters would run actions.
But, at times it can be useful to run an action when an argument does not
expect any parameters.

Closes #104

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-10-27 09:02:33 -07:00
Sean Robinson
748bc95cf5 Rename inner scope variables to differ from outer scope
These variables with the same name are not the same variables because of
scope rules.  While the compiler is not confused by this naming, it may
be less readable by someone attempting to edit this code.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-10-27 09:02:33 -07:00
Sean Robinson
58777d8c84 Replace spaces with underscores in example program names
These examples give a false impression that a space in the middle of the
application name is well handled.  While a space might be possible, it
must be escaped in shells, i.e. a common environment for a CLI argument
parser.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-10-27 09:02:33 -07:00
Sean Robinson
8772b37aab Update examples from exit() to std::exit()
argparse seems to use the "std::" qualifier for std namespace members,
continue that in the documentation.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-10-27 09:02:33 -07:00
Pranav
c9e2958a6c
Merge pull request #143 from skrobinson/fix-copy-misparsed
Fix copying mIsParsed
2021-10-27 10:50:47 -05:00
Sean Robinson
500bc9277e Add ArgumentParser::mIsParsed to copied members
MSVC 19.16 appears to be doing a copy rather than a move in
test_const_correct.  The copy ctor does not handle mIsParsed, so the
initial false value is kept.  This commit adds copying mIsParsed during
copy construction.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-10-27 07:35:52 -07:00
Sean Robinson
af6bbc1d47 Skip --version test until it can be made to work
Because program.parse_args( { "test", "--version" }) calls std::exit(0),
the REQUIRE line never runs and this test is less useful.  Because tests
execution stops here, the doctest status report is not output.  If
--version can be made to not exit during this test, then the test could
be restored.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-10-27 07:33:22 -07:00
Yoshihiro Hokazono
14abaa47d9 Use member initializer list to SizeRange ctor 2021-09-16 08:01:27 +09:00
Yoshihiro Hokazono
bec93acaa7 Avoid use ALL_CAPS for enumerators 2021-09-16 08:01:26 +09:00
Yoshihiro Hokazono
8845260885 Add test for reversed order nargs 2021-09-16 08:01:25 +09:00
Yoshihiro Hokazono
bb115c0419 Add test for variable nargs 2021-09-16 08:01:24 +09:00
Yoshihiro Hokazono
aae2e9347a Add another test for remaining 2021-09-16 08:01:23 +09:00
Yoshihiro Hokazono
2cfe115dfb Change test for remaining to test for * nargs 2021-09-16 08:01:22 +09:00
Yoshihiro Hokazono
10ddd393b6 Fix tests for remaining 2021-09-16 08:01:20 +09:00