Browse Source

WIP: Keep track of implicitly adding args

improve/error-messages
Martchus 4 years ago
parent
commit
3501fe20b8
  1. 4
      application/argumentparser.cpp
  2. 8
      application/argumentparser.h

4
application/argumentparser.cpp

@ -240,13 +240,13 @@ void ArgumentReader::read(ArgumentVector &args)
}
}
// use the first default argument which is not already present if there is still no match
// use the first implicit argument which is not already present if there is still no match
if (!matchingArg && (!completionMode || (argv + 1 != end))) {
const bool uncombinableMainArgPresent = parentArg ? false : parser.isUncombinableMainArgPresent();
for (Argument *arg : args) {
if (arg->isImplicit() && !arg->isPresent() && !arg->wouldConflictWithArgument()
&& (!uncombinableMainArgPresent || !arg->isMainArgument())) {
(matchingArg = arg)->m_occurrences.emplace_back(index, parentPath, parentArg);
(matchingArg = arg)->m_occurrences.emplace_back(Argument::implicitOccurrence, parentPath, parentArg);
break;
}
}

8
application/argumentparser.h

@ -245,6 +245,13 @@ public:
*/
static constexpr std::size_t varValueCount = std::numeric_limits<std::size_t>::max();
/*!
* \brief Indicates an implicit occurrence of an argument.
* \return This value is returned by Argument::index() if the argument has been implicitely added.
* \sa isImplicit(), setImplicit()
*/
static constexpr std::size_t implicitOccurrence = std::numeric_limits<std::size_t>::max();
private:
bool matchesDenotation(const char *denotation, size_t denotationLength) const;
@ -556,6 +563,7 @@ inline std::size_t Argument::occurrences() const
/*!
* \brief Returns the indices of the argument's occurences which could be detected when parsing.
* \remarks Might return Argument::implicitOccurrence in case the argument has been implicitely added.
*/
inline std::size_t Argument::index(std::size_t occurrence) const
{

Loading…
Cancel
Save