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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
These were respectively reported as constParameter and functionConst
style issues by cppcheck.
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
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>
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>
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.
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>
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#119Closes#138Closes#139
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
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>
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>
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>
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>
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>
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>