forked from p-ranav/argparse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1st version of handling variable length nargs
To handle variable length nargs, I replaced mNumArgs with mNumArgsRange. I defined SizeRange class for mNumArgsRange, which has simply min and max std::size_t member. To concentrate on this big change, I tentatively deleted remaining feature, which was originally implemented in the way that mNumArgs = -1 internally and maybe_args() -> Optional wrap method. Library users may make use of 4 types of interface to set mNumArgsRange. 1. nargs(std::size_t) 2. nargs(std::size_t, std::size_t) 3. nargs(SizeRange) 4. nargs(NArgsPattern) 1. is expected to behave same as original. This mthod sets min=max SizeRange to mNumArgsRange, which is actually, not a range, but an "exact" number. 2. sets min and max. 3. uses SizeRange class. This interface may be unnecessary. It is also an option to delete this method and make SizeRange class internal. 4. is provided to set common patterns. In Python, they are "?", "*" and "+". NArgsPattern is an enum class for type safety. std::string interface is also an option to mimic Python argparse. char interface would be ambiguous with 1. Changes on consume method is important. The parser tries to consume args until the count reaches mNumArgsRanges::max or it meets another optional like string. If consumed args count is under mNumArgsRanges::min, the parser fails. Now, when the required number of arguments are not provided, the parser will fail. So, we have to take care of get() method as well. get() failed when argument count is 0 and default value not provided. But now there are 0..1 or 0..* nargs are OK. So this behaviour has to be fixed. When T is container_v, it returns empty container. I implemented validate method so that it shows kind message.
- Loading branch information
Showing
1 changed file
with
125 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters