mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-03 22:54:39 +00:00
Fixed semantics issue b/w optional and positional. Saving positional arguments as a vector in ArgumentParser
This commit is contained in:
parent
965e4ad43c
commit
8e393bdda9
@ -46,7 +46,7 @@ struct Argument {
|
|||||||
std::vector<std::any> mValues;
|
std::vector<std::any> mValues;
|
||||||
std::vector<std::string> mRawValues;
|
std::vector<std::string> mRawValues;
|
||||||
size_t mNumArgs;
|
size_t mNumArgs;
|
||||||
bool mIsPositional;
|
bool mIsOptional;
|
||||||
|
|
||||||
Argument() :
|
Argument() :
|
||||||
mNames({}),
|
mNames({}),
|
||||||
@ -55,7 +55,7 @@ struct Argument {
|
|||||||
mValues({}),
|
mValues({}),
|
||||||
mRawValues({}),
|
mRawValues({}),
|
||||||
mNumArgs(1),
|
mNumArgs(1),
|
||||||
mIsPositional(false) {}
|
mIsOptional(false) {}
|
||||||
|
|
||||||
Argument& help(const std::string& aHelp) {
|
Argument& help(const std::string& aHelp) {
|
||||||
mHelp = aHelp;
|
mHelp = aHelp;
|
||||||
@ -148,13 +148,12 @@ class ArgumentParser {
|
|||||||
tArgument->mNames.push_back(value);
|
tArgument->mNames.push_back(value);
|
||||||
add_argument_internal(tArgument, Fargs...);
|
add_argument_internal(tArgument, Fargs...);
|
||||||
|
|
||||||
bool positional = false;
|
|
||||||
for (auto& mName : tArgument->mNames) {
|
for (auto& mName : tArgument->mNames) {
|
||||||
if (starts_with(mName, "--") || starts_with(mName, "-"))
|
if (starts_with(mName, "--") || starts_with(mName, "-"))
|
||||||
tArgument->mIsPositional = true;
|
tArgument->mIsOptional = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tArgument->mIsPositional)
|
if (!tArgument->mIsOptional)
|
||||||
mPositionalArguments.push_back(tArgument);
|
mPositionalArguments.push_back(tArgument);
|
||||||
|
|
||||||
for (auto& mName : tArgument->mNames) {
|
for (auto& mName : tArgument->mNames) {
|
||||||
|
Loading…
Reference in New Issue
Block a user