Commit Graph

434 Commits

Author SHA1 Message Date
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
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