Commit Graph

381 Commits

Author SHA1 Message Date
Sean Robinson
f0d68de134 Confirm arguments are parsed before allowing ArgumentParser::get
If the developer forgot to call ArgumentParser::parse_args<>, attempts to
use ::get, ::present, etc., would raise "No value provided...".  With this
change, the error better describes what went wrong.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-09-14 09:55:03 -07:00
Sean Robinson
6344b5dcc7 Add argument name in exception thrown by Argument::consume
Here, the user gave an argument name but failed to provide the required
parameters to the argument.  Tell the user which argument wants more.

This is an API change that may affect programs trying to match the
specific "Too few arguments" message.  The new error message appends the
user-supplied argument that caused the error.

A solution which works with both versions is to look for "Too few
arguments" at the beginning of the error message.

- if (err.what() == "Too few arguments")
+ if (std:string(err.what()).rfind("Too few arguments", 0) == 0)

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-09-14 09:54:43 -07:00
Sean Robinson
1c2fd8726d Add argument name in exception thrown by Argument::get
As the user did not include the argument, the longest name for the unused
argument is in the last position of mNames.

This is an API change that may affect programs trying to match the
specific "No value provided" message.  The new error message appends the
argument that caused the error.

A solution which works with both versions is to look for "No value
provided" at the beginning of the error message.

- if (err.what() == "No value provided")
+ if (std:string(err.what()).rfind("No value provided", 0) == 0)

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-09-14 09:51:10 -07:00
Sean Robinson
97993666ab Add tests for ArgumentParser::get
These test the API shown in README.md, rather than the Argument::get
function that does most of the work.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-09-14 09:46:22 -07:00
Sean Robinson
b6cedf4d56 Add test case for missing argument value
While it's good to test around error conditions, the main purpose of this
test is to catch future changes in the error type and message.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-09-14 09:44:39 -07:00
Sean Robinson
67d56afef8 Add test case for missing expected positional argument
This fills a tiny gap in the positional_arguments suite.  Most existing
tests have positional arguments.  The one case without an argument uses
Argument::remaining so that ArgumentParserArgument::parse_args does not
throw, instead ArgumentParser::get<> throws std::logic_error.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-09-14 09:44:35 -07:00
Pranav
b33ba4fb5d
Merge pull request #127 from hokacci/feature/flexible-get-syntax
Make get syntax flexible
2021-09-14 09:36:07 -05:00
Pranav
0f392ae057
Merge pull request #130 from skrobinson/fix-cmake-warning
Add CMake project name
2021-09-14 09:35:28 -05:00
Pranav
ffe619fe08
Merge pull request #129 from skrobinson/wip-gh-action-pr
Add GitHub Action to run tests on pull request
2021-09-14 09:35:14 -05:00
Sean Robinson
335e6272bd Add GitHub Action to run tests on pull request
Run tests on Apple macOS, MS Windows, and Ubuntu Linux hosts.

macOS-hosted tests are only run on latest, which is currently macOS 10.15.
GH will eventually update latest to macOS 11 and we can look at expanding
to two versions of macOS.

Windows-hosted tests run on Windows Server 2016 and latest.

Ubuntu-hosted tests only run on latest because g++ fails to build argparse
on ubuntu-18.04 (GCC 8) since charconv was added in commit ea2f16d2.  But,
Ubuntu-hosted tests do run with g++ and clang++.

Closes #128.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-09-13 14:17:19 -07:00
Yoshihiro Hokazono
971f687a17 Kind error message 2021-09-13 07:08:37 +09:00
Yoshihiro Hokazono
8727c132fc get("out") and get("--out") are both avaibale 2021-09-13 07:07:20 +09:00
Sean Robinson
2f59260e84 Add CMake project name
This silences the following warning:

  No project() command is present.  The top-level CMakeLists.txt file must
  contain a literal, direct call to the project() command.  Add a line of
  code such as

    project(ProjectName)

  near the top of the file, but after cmake_minimum_required().

  CMake is pretending there is a "project(Project)" command on the first
  line.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-09-09 13:43:21 -07:00
Pranav
b0cb28ab17
Merge pull request #115 from HydrArgs/cpack
Some cleanup in CPack packaging
2021-09-01 09:16:48 -05:00
Pranav
8af52044cf
Merge pull request #123 from skrobinson/rev-chars_format-update
Revert "Use std::chars_format rather than local copy"
2021-08-27 06:52:07 -05:00
Sean Robinson
37dc4f20ec Revert "Use std::chars_format rather than local copy"
It's too early to use std::chars_format as there is not wide enough
support in stdlib implementations.  After the following stdlib become our
supported versions, this can be revisited.

GCC >= 10.1.0
Clang >= 7.0.0 (already our minimum)
MSVC >= 19.4

Reverts commit 1c61082a4c.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-08-26 06:55:36 -07:00
Pranav
5f8879f1da
Merge pull request #120 from skrobinson/wip-chars_format-update
Use std::chars_format rather than local copy
2021-08-24 19:21:40 -05:00
Pranav
4d03fc04b2
Merge pull request #121 from skrobinson/wip-add-scan-docs
Document and use Argument.scan where possible
2021-08-24 19:20:04 -05:00
Sean Robinson
a8900c2019 Replace simple type-converting Argument.action with Argument.scan in tests
Argument.scan handles simple string to numeric type conversions, removing
the need to create a lambda.  Argument.action is still necessary for more
complex conversions and those are left unchanged.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-08-24 09:25:49 -07:00
Sean Robinson
38a4a1a755 Replace simple type-converting Argument.action with Argument.scan in README
To better show the built-in conversion to a primitive type, use .scan in
examples.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-08-24 09:25:49 -07:00
Sean Robinson
bcc1f5adea Add documentation for Argument.scan
IMHO, the .scan function and its supporting functions are beautiful
metaprogramming that needs to be more visible to argparse users.  As a
start, document the function, with simple examples.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-08-24 09:25:49 -07:00
Sean Robinson
1c61082a4c Use std::chars_format rather than local copy
I believe the Supported Toolchains all now include <charconv> (and
std::chars_format) and we can use the stdlib-defined values.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-08-24 09:20:50 -07:00
KOLANICH
7fad8faf8c Some cleanup in CPack packaging 2021-08-16 13:18:00 +03:00
Pranav
ccf3920ce2
Merge pull request #108 from Bedzior/const-correct-argument-parser
Const-correct ArgumentParser
2021-08-07 07:22:12 -05:00
Pranav
6b1f4652ad
Merge pull request #110 from Chuvi-w/size_t_to_std_size_t
Replace size_t to std::size_t.
2021-08-05 08:25:05 -05:00
Chuvi
a3f164bcc7 Replace size_t to std::size_t.
https://github.com/p-ranav/argparse/pull/109#issuecomment-892943775
2021-08-05 16:06:06 +03:00
Pranav
801e2ef343
Merge pull request #109 from Chuvi-w/fix_std_min_conflict
Fix std::min conflict with min/max definitions from windows.h
2021-08-05 07:23:43 -05:00
Chuvi
0652496435
Use std::min type specialisation 2021-08-04 19:43:20 +03:00
Chuvi
14fd4c6d5b Fix std::min conflict with min/max definitions from windows.h 2021-08-04 13:54:46 +03:00
Rafal Bedzkowski
5841bca894 Introduce separate const-correctness test 2021-08-03 22:12:05 +02:00
Rafal Bedzkowski
4ede429264 Const-correct ArgumentParser 2021-08-02 17:21:46 +02:00
Pranav
e1ea7ec50a
Merge pull request #107 from KOLANICH/cpack
Added packaging using CPack and generation of pkg-config files.
2021-07-21 07:52:28 -05:00
KOLANICH
9ba45adfe2 Added packaging using CPack and generation of pkg-config files.
Fixed installation directory - the lib is architecture-independent and so CMake and pkg-config files should go into <prefix>/lib, not into <prefix>/lib/<arch>
2021-07-21 13:11:52 +03:00
Pranav
64dd67c758
Merge pull request #103 from kfsone/optional-v
Allow user to limit version argument to --version
2021-06-04 19:03:00 -05:00
Oliver 'kfsone' Smith
38b1b8114e Allow user to limit version argument to --version 2021-06-04 16:56:22 -07:00
Pranav
1344889acf
Merge pull request #100 from skrobinson/wip-is_used-method
Add ArgumentParser.is_used to discern user-supplied values from defaults
2021-04-07 16:58:05 -05:00
Sean Robinson
3efd045ea9 Add ArgumentParser.is_used to discern user-supplied values from defaults
.present returns std::nullopt if the optional argument is not given by the
user -- as long as a .default_value is not defined.  With a .default_value,
.present cannot be used to determine if a value is user-provided or the
default.

.is_used fills that role and only returns true if the argument was passed
by the user.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-04-07 14:09:10 -07:00
Pranav
65f2ad4db2
Merge pull request #99 from skrobinson/wip-append-method
Add Argument.append method to allow repeated argument use
2021-04-07 14:26:45 -05:00
Sean Robinson
54d3cda804 Add Argument.append method to allow repeated argument use
The default behavior with optional arguments is to allow only a single use
per invocation.  One alternative is to use .nargs, but this requires
previously knowing, and limiting, the quantity of values.  The .append
method removes the restriction on repeats for a single Argument.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-04-07 11:47:09 -07:00
Pranav
9e9d969814
Merge pull request #98 from skrobinson/wip-clean-ups
misc clean ups
2021-04-07 12:37:36 -05:00
Sean Robinson
0fe17e22f6 Replace integers with bool value keywords
While the implicit conversions from `1` to `true` work correctly, this
avoids the conversions.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-04-06 12:07:53 -07:00
Sean Robinson
a711f26045 Remove trailing spaces from README lines
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-04-06 12:07:53 -07:00
Sean Robinson
e371313b87 Update copyright dates and authors
The full list of contributors is available in the git commit log.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-04-06 11:53:19 -07:00
Pranav
165d560b3a
Merge pull request #97 from qoelet/qualify-iterator-functions
Qualify iterator functions
2021-03-25 08:55:17 -05:00
Kenny Shen
c869f20e2b Qualify iterator functions 2021-03-25 12:55:26 +08:00
Pranav
9903a22904
Merge pull request #93 from cekc/nicer-message-for-required
nicer usage text for required arg
2020-12-15 15:06:25 -06:00
Mike Zozu
ed06438faf nicer usage text for required arg 2020-12-15 23:01:07 +03:00
Pranav
68fb9f16d8
Merge pull request #92 from cekc/#88-show-default-value-in-help
Show default value for arg in help message
2020-12-15 13:15:52 -06:00
Mike Zozu
88f1614df6 revert MacOS image change 2020-12-15 22:07:27 +03:00
Mike Zozu
1f9591eabc Merge branch '#88-show-default-value-in-help' of github.com:cekc/argparse into #88-show-default-value-in-help 2020-12-15 22:01:29 +03:00