Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actions with nonary arguments, removable defaults, and some clean ups #142

Merged
merged 6 commits into from
Oct 27, 2021

Conversation

skrobinson
Copy link
Contributor

I've seen several requests to change the behavior of --help and --version with regard to exit() ending program execution. On the way to solving these requests, I needed to add nonary argument actions. This patch series includes other small fixes found along the way.

@skrobinson skrobinson force-pushed the wip-deactivatable-defaults branch 2 times, most recently from 9b93643 to b1e2112 Compare October 26, 2021 19:58
@p-ranav
Copy link
Owner

p-ranav commented Oct 26, 2021

Do you know what the problem is with the CI? CI / windows-2016-msvc (pull_request) is failing?

@skrobinson
Copy link
Contributor Author

Unfortunately, the test failure only shows with windows-2016-msvc.

D:\a\argparse\argparse\test\test_const_correct.cpp(22): FATAL ERROR: REQUIRE( const_parser.get("-f") == "baz" ) THREW exception: "Nothing parsed, no arguments are available."

The MSVC 2019 build runs fine. This may take some time to track down.

@skrobinson skrobinson force-pushed the wip-deactivatable-defaults branch from b1e2112 to 60c3d0b Compare October 27, 2021 16:01
argparse seems to use the "std::" qualifier for std namespace members,
continue that in the documentation.

Signed-off-by: Sean Robinson <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 p-ranav#104

Signed-off-by: Sean Robinson <[email protected]>
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 p-ranav#119
Closes p-ranav#138
Closes p-ranav#139

Signed-off-by: Sean Robinson <[email protected]>
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 <[email protected]>
@skrobinson skrobinson force-pushed the wip-deactivatable-defaults branch from 60c3d0b to 5cceb98 Compare October 27, 2021 16:02
@skrobinson
Copy link
Contributor Author

@p-ranav,

I was able to resolve this faster than I expected. This branch has been rebased on the post-#143 master and now passes tests in our five OS/compiler environments.

While researching the test fails, I saw that the GitHub windows-2016 environment is deprecated will be disabled in early 2022. Sometime before then, I'll submit a PR removing that config from our tests.

@p-ranav p-ranav merged commit b98bf25 into p-ranav:master Oct 27, 2021
@skrobinson skrobinson deleted the wip-deactivatable-defaults branch November 1, 2021 15:52
@skrobinson skrobinson mentioned this pull request Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants