Simplify ArgumentParser::readArgs()
This commit is contained in:
parent
5950aed7ec
commit
8c42a4644b
|
@ -845,12 +845,23 @@ void ArgumentParser::readArgs(int argc, const char *const *argv)
|
||||||
{
|
{
|
||||||
IF_DEBUG_BUILD(verifyArgs(m_mainArgs, std::vector<char>(), std::vector<const char *>());)
|
IF_DEBUG_BUILD(verifyArgs(m_mainArgs, std::vector<char>(), std::vector<const char *>());)
|
||||||
m_actualArgc = 0;
|
m_actualArgc = 0;
|
||||||
if (argc) {
|
|
||||||
// the first argument is the executable name
|
// the first argument is the executable name
|
||||||
|
if (!argc) {
|
||||||
|
m_executable = nullptr;
|
||||||
|
return;
|
||||||
|
}
|
||||||
m_executable = *argv;
|
m_executable = *argv;
|
||||||
|
|
||||||
// check for further arguments
|
// check for further arguments
|
||||||
if (--argc) {
|
if (!--argc) {
|
||||||
|
// no arguments specified -> flag default argument as present if one is assigned
|
||||||
|
if (m_defaultArg) {
|
||||||
|
m_defaultArg->m_occurrences.emplace_back(0);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// if the first argument (after executable name) is "--bash-completion-for", bash completion for the following arguments is requested
|
// if the first argument (after executable name) is "--bash-completion-for", bash completion for the following arguments is requested
|
||||||
bool completionMode = !strcmp(*++argv, "--bash-completion-for");
|
bool completionMode = !strcmp(*++argv, "--bash-completion-for");
|
||||||
unsigned int currentWordIndex;
|
unsigned int currentWordIndex;
|
||||||
|
@ -868,8 +879,7 @@ void ArgumentParser::readArgs(int argc, const char *const *argv)
|
||||||
|
|
||||||
// read specified arguments
|
// read specified arguments
|
||||||
ArgumentReader reader(*this, argv,
|
ArgumentReader reader(*this, argv,
|
||||||
argv + (completionMode ? min(static_cast<unsigned int>(argc), currentWordIndex + 1) : static_cast<unsigned int>(argc)),
|
argv + (completionMode ? min(static_cast<unsigned int>(argc), currentWordIndex + 1) : static_cast<unsigned int>(argc)), completionMode);
|
||||||
completionMode);
|
|
||||||
try {
|
try {
|
||||||
reader.read();
|
reader.read();
|
||||||
NoColorArgument::apply();
|
NoColorArgument::apply();
|
||||||
|
@ -884,15 +894,6 @@ void ArgumentParser::readArgs(int argc, const char *const *argv)
|
||||||
printBashCompletion(argc, argv, currentWordIndex, reader);
|
printBashCompletion(argc, argv, currentWordIndex, reader);
|
||||||
exitFunction(0); // prevent the applicaton to continue with the regular execution
|
exitFunction(0); // prevent the applicaton to continue with the regular execution
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// no arguments specified -> flag default argument as present if one is assigned
|
|
||||||
if (m_defaultArg) {
|
|
||||||
m_defaultArg->m_occurrences.emplace_back(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
m_executable = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
Loading…
Reference in New Issue