Add method to find specified operation

This commit is contained in:
Martchus 2017-09-26 16:46:17 +02:00
parent a1d6c3ba7b
commit 1c450d43a2
2 changed files with 31 additions and 0 deletions

View File

@ -527,6 +527,20 @@ Argument *Argument::wouldConflictWithArgument() const
return nullptr;
}
/*!
* \brief Returns the first operation argument specified by the user or nullptr if no operation has been specified.
* \remarks Only direct sub arguments of this argument are considered.
*/
Argument *Argument::specifiedOperation() const
{
for (Argument *arg : m_subArgs) {
if (arg->denotesOperation() && arg->isPresent()) {
return arg;
}
}
return nullptr;
}
/*!
* \brief Resets this argument and all sub arguments recursively.
* \sa Argument::reset()
@ -743,6 +757,21 @@ void ArgumentParser::resetArgs()
m_actualArgc = 0;
}
/*!
* \brief Returns the first operation argument specified by the user or nullptr if no operation has been specified.
* \remarks Only main arguments are considered. See Argument::specifiedOperation() to check sub arguments of a specific
* argument.
*/
Argument *ArgumentParser::specifiedOperation() const
{
for (Argument *arg : m_mainArgs) {
if (arg->denotesOperation() && arg->isPresent()) {
return arg;
}
}
return nullptr;
}
/*!
* \brief Checks whether at least one uncombinable main argument is present.
*/

View File

@ -199,6 +199,7 @@ public:
void setPreDefinedCompletionValues(const char *preDefinedCompletionValues);
Argument *conflictsWithArgument() const;
Argument *wouldConflictWithArgument() const;
Argument *specifiedOperation() const;
void reset();
void resetRecursively();
@ -250,6 +251,7 @@ public:
void setUnknownArgumentBehavior(UnknownArgumentBehavior behavior);
Argument *defaultArgument() const;
void setDefaultArgument(Argument *argument);
Argument *specifiedOperation() const;
void checkConstraints();
void invokeCallbacks();
bool isUncombinableMainArgPresent() const;