mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-04 07:04:39 +00:00
Fixes issue #6
This commit is contained in:
parent
0b1a5b71f8
commit
88eca55b06
@ -556,28 +556,38 @@ class ArgumentParser {
|
|||||||
// The user provides ./main -aux ...
|
// The user provides ./main -aux ...
|
||||||
// Here -aux is a compound optional argument
|
// Here -aux is a compound optional argument
|
||||||
std::string tCompoundArgument = std::string(argv[i]);
|
std::string tCompoundArgument = std::string(argv[i]);
|
||||||
for (size_t j = 1; j < tCompoundArgument.size(); j++) {
|
if (tCompoundArgument.size() > 1 && tCompoundArgument[0] == '-' && tCompoundArgument[1] != '-') {
|
||||||
std::string tArgument(1, tCompoundArgument[j]);
|
for (size_t j = 1; j < tCompoundArgument.size(); j++) {
|
||||||
size_t tNumArgs = 0;
|
std::string tArgument(1, tCompoundArgument[j]);
|
||||||
std::map<std::string, std::shared_ptr<Argument>>::iterator tIterator = mArgumentMap.find("-" + tArgument);
|
size_t tNumArgs = 0;
|
||||||
if (tIterator != mArgumentMap.end()) {
|
std::map<std::string, std::shared_ptr<Argument>>::iterator tIterator = mArgumentMap.find("-" + tArgument);
|
||||||
auto tArgumentObject = tIterator->second;
|
if (tIterator != mArgumentMap.end()) {
|
||||||
tNumArgs = tArgumentObject->mNumArgs;
|
auto tArgumentObject = tIterator->second;
|
||||||
}
|
tNumArgs = tArgumentObject->mNumArgs;
|
||||||
std::vector<std::string> tArgumentsForRecursiveParsing = { "", "-" + tArgument };
|
|
||||||
while (tNumArgs > 0 && i < argc) {
|
|
||||||
i += 1;
|
|
||||||
if (i < argc) {
|
|
||||||
tArgumentsForRecursiveParsing.push_back(argv[i]);
|
|
||||||
tNumArgs -= 1;
|
|
||||||
}
|
}
|
||||||
|
std::vector<std::string> tArgumentsForRecursiveParsing = { "", "-" + tArgument };
|
||||||
|
while (tNumArgs > 0 && i < argc) {
|
||||||
|
i += 1;
|
||||||
|
if (i < argc) {
|
||||||
|
tArgumentsForRecursiveParsing.push_back(argv[i]);
|
||||||
|
tNumArgs -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parse_args_internal(tArgumentsForRecursiveParsing);
|
||||||
}
|
}
|
||||||
parse_args_internal(tArgumentsForRecursiveParsing);
|
}
|
||||||
|
else {
|
||||||
|
std::cout << "warning: unrecognized optional argument " << tCompoundArgument << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// This is a positional argument.
|
// This is a positional argument.
|
||||||
// Parse and save into mPositionalArguments vector
|
// Parse and save into mPositionalArguments vector
|
||||||
|
if (mNextPositionalArgument >= mPositionalArguments.size()) {
|
||||||
|
std::cout << "error: unexpected positional argument " << argv[i] << std::endl;
|
||||||
|
print_help();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
auto tArgument = mPositionalArguments[mNextPositionalArgument];
|
auto tArgument = mPositionalArguments[mNextPositionalArgument];
|
||||||
auto tCount = tArgument->mNumArgs - tArgument->mRawValues.size();
|
auto tCount = tArgument->mNumArgs - tArgument->mRawValues.size();
|
||||||
while (tCount > 0) {
|
while (tCount > 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user