mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-04 15:14:39 +00:00
First check for positional, then optional and compound
This commit is contained in:
parent
44bef34e79
commit
d95f9d9f14
@ -204,6 +204,10 @@ public:
|
|||||||
return (!aName.empty() && aName[0] == '-');
|
return (!aName.empty() && aName[0] == '-');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool is_positional(const std::string& aName) {
|
||||||
|
return !is_optional(aName);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Getter for template non-container types
|
* Getter for template non-container types
|
||||||
* @throws std::logic_error in case of incompatible types
|
* @throws std::logic_error in case of incompatible types
|
||||||
@ -436,18 +440,17 @@ class ArgumentParser {
|
|||||||
if (tCurrentArgument == Argument::mHelpOption || tCurrentArgument == Argument::mHelpOptionLong) {
|
if (tCurrentArgument == Argument::mHelpOption || tCurrentArgument == Argument::mHelpOptionLong) {
|
||||||
throw std::runtime_error("help called");
|
throw std::runtime_error("help called");
|
||||||
}
|
}
|
||||||
auto tIterator = mArgumentMap.find(tCurrentArgument);
|
if (Argument::is_positional(tCurrentArgument)) {
|
||||||
if (tIterator != mArgumentMap.end()) {
|
|
||||||
auto tArgument = tIterator->second;
|
|
||||||
it = tArgument->consume(std::next(it), end, tCurrentArgument);
|
|
||||||
}
|
|
||||||
else if (!Argument::is_optional(tCurrentArgument)) {
|
|
||||||
if (mNextPositionalArgument >= mPositionalArguments.size()) {
|
if (mNextPositionalArgument >= mPositionalArguments.size()) {
|
||||||
throw std::runtime_error("Maximum number of positional arguments exceeded");
|
throw std::runtime_error("Maximum number of positional arguments exceeded");
|
||||||
}
|
}
|
||||||
auto tArgument = mPositionalArguments[mNextPositionalArgument++];
|
auto tArgument = mPositionalArguments[mNextPositionalArgument++];
|
||||||
it = tArgument->consume(it, end);
|
it = tArgument->consume(it, end);
|
||||||
}
|
}
|
||||||
|
else if (auto tIterator = mArgumentMap.find(tCurrentArgument); tIterator != mArgumentMap.end()) {
|
||||||
|
auto tArgument = tIterator->second;
|
||||||
|
it = tArgument->consume(std::next(it), end, tCurrentArgument);
|
||||||
|
}
|
||||||
else { // TODO: compound optional arguments
|
else { // TODO: compound optional arguments
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user