mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-04 15:14:39 +00:00
Don't call print_help inside ArgumentParser
This commit is contained in:
parent
42ff186743
commit
12ad27f9c3
@ -483,7 +483,6 @@ class ArgumentParser {
|
|||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
auto tCurrentArgument = std::string(argv[i]);
|
auto tCurrentArgument = std::string(argv[i]);
|
||||||
if (tCurrentArgument == "-h" || tCurrentArgument == "--help") {
|
if (tCurrentArgument == "-h" || tCurrentArgument == "--help") {
|
||||||
print_help();
|
|
||||||
throw std::runtime_error("help called");
|
throw std::runtime_error("help called");
|
||||||
}
|
}
|
||||||
auto tIterator = mArgumentMap.find(argv[i]);
|
auto tIterator = mArgumentMap.find(argv[i]);
|
||||||
@ -566,7 +565,6 @@ class ArgumentParser {
|
|||||||
if (mNextPositionalArgument >= mPositionalArguments.size()) {
|
if (mNextPositionalArgument >= mPositionalArguments.size()) {
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
stream << "error: unexpected positional argument " << argv[i] << std::endl;
|
stream << "error: unexpected positional argument " << argv[i] << std::endl;
|
||||||
print_help();
|
|
||||||
throw std::runtime_error(stream.str());
|
throw std::runtime_error(stream.str());
|
||||||
}
|
}
|
||||||
auto tArgument = mPositionalArguments[mNextPositionalArgument];
|
auto tArgument = mPositionalArguments[mNextPositionalArgument];
|
||||||
@ -610,7 +608,6 @@ class ArgumentParser {
|
|||||||
stream << "error: " << tArgument->mUsedName << ": expected "
|
stream << "error: " << tArgument->mUsedName << ": expected "
|
||||||
<< tArgument->mNumArgs << (tArgument->mNumArgs == 1 ? " argument. " : " arguments. ")
|
<< tArgument->mNumArgs << (tArgument->mNumArgs == 1 ? " argument. " : " arguments. ")
|
||||||
<< tArgument->mValues.size() << " provided.\n" << std::endl;
|
<< tArgument->mValues.size() << " provided.\n" << std::endl;
|
||||||
print_help();
|
|
||||||
throw std::runtime_error(stream.str());
|
throw std::runtime_error(stream.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -626,7 +623,6 @@ class ArgumentParser {
|
|||||||
stream << "error: " << tArgument->mUsedName << ": expected "
|
stream << "error: " << tArgument->mUsedName << ": expected "
|
||||||
<< tArgument->mNumArgs << (tArgument->mNumArgs == 1 ? " argument. " : " arguments. ")
|
<< tArgument->mNumArgs << (tArgument->mNumArgs == 1 ? " argument. " : " arguments. ")
|
||||||
<< tArgument->mValues.size() << " provided.\n" << std::endl;
|
<< tArgument->mValues.size() << " provided.\n" << std::endl;
|
||||||
print_help();
|
|
||||||
throw std::runtime_error(stream.str());
|
throw std::runtime_error(stream.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -679,6 +675,7 @@ try { \
|
|||||||
parser.parse_args(argc, argv); \
|
parser.parse_args(argc, argv); \
|
||||||
} catch (const std::runtime_error& err) { \
|
} catch (const std::runtime_error& err) { \
|
||||||
std::cerr << err.what() << std::endl; \
|
std::cerr << err.what() << std::endl; \
|
||||||
|
parser.print_help(); \
|
||||||
exit(0); \
|
exit(0); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user