mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-04 07:04:39 +00:00
Fixed minor bug with validating optional arguments. Added mIsUsed to Argument class
This commit is contained in:
parent
03bf4f294d
commit
63a6763489
@ -94,7 +94,8 @@ public:
|
|||||||
mValues({}),
|
mValues({}),
|
||||||
mRawValues({}),
|
mRawValues({}),
|
||||||
mNumArgs(1),
|
mNumArgs(1),
|
||||||
mIsOptional(false) {}
|
mIsOptional(false),
|
||||||
|
mIsUsed(false) {}
|
||||||
|
|
||||||
Argument& help(const std::string& aHelp) {
|
Argument& help(const std::string& aHelp) {
|
||||||
mHelp = aHelp;
|
mHelp = aHelp;
|
||||||
@ -274,6 +275,7 @@ public:
|
|||||||
std::vector<std::string> mRawValues;
|
std::vector<std::string> mRawValues;
|
||||||
size_t mNumArgs;
|
size_t mNumArgs;
|
||||||
bool mIsOptional;
|
bool mIsOptional;
|
||||||
|
bool mIsUsed; // relevant for optional arguments. True if used by user
|
||||||
};
|
};
|
||||||
|
|
||||||
class ArgumentParser {
|
class ArgumentParser {
|
||||||
@ -518,6 +520,7 @@ class ArgumentParser {
|
|||||||
if (tIterator != mArgumentMap.end()) {
|
if (tIterator != mArgumentMap.end()) {
|
||||||
// Start parsing optional argument
|
// Start parsing optional argument
|
||||||
auto tArgument = tIterator->second;
|
auto tArgument = tIterator->second;
|
||||||
|
tArgument->mIsUsed = true;
|
||||||
auto tCount = tArgument->mNumArgs;
|
auto tCount = tArgument->mNumArgs;
|
||||||
|
|
||||||
// Check to see if implicit value should be used
|
// Check to see if implicit value should be used
|
||||||
@ -620,7 +623,7 @@ class ArgumentParser {
|
|||||||
// Check if all user-provided optional argument values are parsed correctly
|
// Check if all user-provided optional argument values are parsed correctly
|
||||||
for (size_t i = 0; i < mOptionalArguments.size(); i++) {
|
for (size_t i = 0; i < mOptionalArguments.size(); i++) {
|
||||||
auto tArgument = mOptionalArguments[i];
|
auto tArgument = mOptionalArguments[i];
|
||||||
if (tArgument->mNumArgs > 0) {
|
if (tArgument->mIsUsed && tArgument->mNumArgs > 0) {
|
||||||
if (tArgument->mValues.size() != tArgument->mNumArgs) {
|
if (tArgument->mValues.size() != tArgument->mNumArgs) {
|
||||||
// All cool if there's a default value to return
|
// All cool if there's a default value to return
|
||||||
// If no default value, then there's a problem
|
// If no default value, then there's a problem
|
||||||
|
Loading…
Reference in New Issue
Block a user