| 1 | #cxx . . $ `<file>/application/argumentparser.cpp`/include "./argumentparser.h"cxx . . $ `<file>/application/argumentparser.h`/ |
| 2 | #include "./argumentparserprivate.h"cxx . . $ `<file>/application/argumentparserprivate.h`/ |
| 3 | #include "./commandlineutils.h"cxx . . $ `<file>/application/commandlineutils.h`/ |
| 4 | |
| 5 | #include "../conversion/stringbuilder.h"cxx . . $ `<file>/conversion/stringbuilder.h`/ |
| 6 | #include "../conversion/stringconversion.h"cxx . . $ `<file>/conversion/stringconversion.h`/ |
| 7 | #include "../io/ansiescapecodes.h"cxx . . $ `<file>/io/ansiescapecodes.h`/ |
| 8 | #include "../io/path.h"cxx . . $ `<file>/io/path.h`/ |
| 9 | #include "../misc/levenshtein.h"cxx . . $ `<file>/misc/levenshtein.h`/ |
| 10 | #include "../misc/parseerror.h"cxx . . $ `<file>/misc/parseerror.h`/ |
| 11 | |
| 12 | #include <algorithm> |
| 13 | #include <cstdlib> |
| 14 | #include <cstring> |
| 15 | #include <iostream> |
| 16 | #include <set> |
| 17 | #include <sstream> |
| 18 | #include <string> |
| 19 | |
| 20 | #ifdef CPP_UTILITIES_USE_STANDARD_FILESYSTEMcxx . . $ `<built-in>:484:9`! |
| 21 | #include <filesystem> |
| 22 | #endif |
| 23 | |
| 24 | using namespace std; |
| 25 | using namespace stdcxx . . $ std/::placeholders; |
| 26 | using namespace stdcxx . . $ std/::literals; |
| 27 | using namespace CppUtilitiescxx . . $ CppUtilities/::EscapeCodes; |
| 28 | |
| 29 | /*! |
| 30 | * \namespace CppUtilities |
| 31 | * \brief Contains all utilities provided by the c++utilities library. |
| 32 | */ |
| 33 | namespace CppUtilitiescxx . . $ CppUtilities/ { |
| 34 | |
| 35 | /*! |
| 36 | * \brief The ArgumentDenotationType enum specifies the type of a given argument denotation. |
| 37 | */ |
| 38 | enum ArgumentDenotationTypecxx . . $ CppUtilities/ArgumentDenotationType# : unsigned char { |
| 39 | Valuecxx . . $ CppUtilities/Value. = 0, /**< parameter value */ |
| 40 | Abbreviationcxx . . $ CppUtilities/Abbreviation. = 1, /**< argument abbreviation */ |
| 41 | FullNamecxx . . $ CppUtilities/FullName. = 2 /**< full argument name */ |
| 42 | }; |
| 43 | |
| 44 | /*! |
| 45 | * \brief The ArgumentCompletionInfo struct holds information internally used for shell completion and suggestions. |
| 46 | */ |
| 47 | struct ArgumentCompletionInfocxx . . $ CppUtilities/ArgumentCompletionInfo# { |
| 48 | ArgumentCompletionInfocxx . . $ CppUtilities/ArgumentCompletionInfo#ArgumentCompletionInfo(a92acb73639bd8f5).(const ArgumentReadercxx . . $ CppUtilities/ArgumentReader# &reader); |
| 49 | |
| 50 | const Argumentcxx . . $ CppUtilities/Argument# *const lastDetectedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArg.; |
| 51 | size_t lastDetectedArgIndexcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArgIndex. = 0; |
| 52 | vectorcxx . . $ std/vector#<Argumentcxx . . $ CppUtilities/Argument# *> lastDetectedArgPathcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArgPath.; |
| 53 | listcxx . . $ std/__cxx11/list#<const Argumentcxx . . $ CppUtilities/Argument# *> relevantArgscxx . . $ CppUtilities/ArgumentCompletionInfo#relevantArgs.; |
| 54 | listcxx . . $ std/__cxx11/list#<const Argumentcxx . . $ CppUtilities/Argument# *> relevantPreDefinedValuescxx . . $ CppUtilities/ArgumentCompletionInfo#relevantPreDefinedValues.; |
| 55 | const char *const *lastSpecifiedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastSpecifiedArg. = nullptr; |
| 56 | unsigned int lastSpecifiedArgIndexcxx . . $ CppUtilities/ArgumentCompletionInfo#lastSpecifiedArgIndex. = 0; |
| 57 | bool nextArgumentOrValuecxx . . $ CppUtilities/ArgumentCompletionInfo#nextArgumentOrValue. = false; |
| 58 | bool completeFilescxx . . $ CppUtilities/ArgumentCompletionInfo#completeFiles. = false, completeDirscxx . . $ CppUtilities/ArgumentCompletionInfo#completeDirs. = false; |
| 59 | }; |
| 60 | |
| 61 | /*! |
| 62 | * \brief Constructs a new completion info for the specified \a reader. |
| 63 | * \remarks Only assigns some defaults. Use ArgumentParser::determineCompletionInfo() to populate the struct with actual data. |
| 64 | */ |
| 65 | ArgumentCompletionInfocxx . . $ CppUtilities/ArgumentCompletionInfo#::ArgumentCompletionInfocxx . . $ CppUtilities/ArgumentCompletionInfo#ArgumentCompletionInfo(a92acb73639bd8f5).(const ArgumentReadercxx . . $ CppUtilities/ArgumentReader# &reader) |
| 66 | : lastDetectedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArg.(reader.lastArgcxx . . $ CppUtilities/ArgumentReader#lastArg.) |
| 67 | { |
| 68 | } |
| 69 | |
| 70 | /// \cond |
| 71 | struct ArgumentSuggestioncxx . . $ CppUtilities/ArgumentSuggestion# { |
| 72 | ArgumentSuggestioncxx . . $ CppUtilities/ArgumentSuggestion#ArgumentSuggestion(12d7fb8e6b484263).(const char *unknownArg, size_t unknownArgSize, const char *suggestion, bool hasDashPrefix); |
| 73 | ArgumentSuggestioncxx . . $ CppUtilities/ArgumentSuggestion#ArgumentSuggestion(40163010065b39bd).(const char *unknownArg, size_t unknownArgSize, const char *suggestion, size_t suggestionSize, bool hasDashPrefix); |
| 74 | bool operatorcxx . . $ CppUtilities/ArgumentSuggestion#`operator<`(c4d65ca16f50c897).<(const ArgumentSuggestioncxx . . $ CppUtilities/ArgumentSuggestion# &other) const; |
| 75 | bool operatorcxx . . $ CppUtilities/ArgumentSuggestion#`operator==`(c4d65ca16f50c897).==(const ArgumentSuggestioncxx . . $ CppUtilities/ArgumentSuggestion# &other) const; |
| 76 | void addTocxx . . $ CppUtilities/ArgumentSuggestion#addTo(2da8636ff036a360).(multisetcxx . . $ std/multiset#<ArgumentSuggestioncxx . . $ CppUtilities/ArgumentSuggestion#> &suggestions, size_t limit) const; |
| 77 | |
| 78 | const char *const suggestioncxx . . $ CppUtilities/ArgumentSuggestion#suggestion.; |
| 79 | const size_t suggestionSizecxx . . $ CppUtilities/ArgumentSuggestion#suggestionSize.; |
| 80 | const size_t editingDistancecxx . . $ CppUtilities/ArgumentSuggestion#editingDistance.; |
| 81 | const bool hasDashPrefixcxx . . $ CppUtilities/ArgumentSuggestion#hasDashPrefix.; |
| 82 | }; |
| 83 | |
| 84 | ArgumentSuggestioncxx . . $ CppUtilities/ArgumentSuggestion#::ArgumentSuggestioncxx . . $ CppUtilities/ArgumentSuggestion#ArgumentSuggestion(40163010065b39bd).(const char *unknownArg, size_t unknownArgSize, const char *suggestion, size_t suggestionSize, bool isOperation) |
| 85 | : suggestioncxx . . $ CppUtilities/ArgumentSuggestion#suggestion.(suggestion) |
| 86 | , suggestionSizecxx . . $ CppUtilities/ArgumentSuggestion#suggestionSize.(suggestionSize) |
| 87 | , editingDistancecxx . . $ CppUtilities/ArgumentSuggestion#editingDistance.(computeDamerauLevenshteinDistancecxx . . $ CppUtilities/computeDamerauLevenshteinDistance(de56e73a02f050dc).(unknownArg, unknownArgSize, suggestion, suggestionSize)) |
| 88 | , hasDashPrefixcxx . . $ CppUtilities/ArgumentSuggestion#hasDashPrefix.(isOperation) |
| 89 | { |
| 90 | } |
| 91 | |
| 92 | ArgumentSuggestioncxx . . $ CppUtilities/ArgumentSuggestion#::ArgumentSuggestioncxx . . $ CppUtilities/ArgumentSuggestion#ArgumentSuggestion(12d7fb8e6b484263).(const char *unknownArg, size_t unknownArgSize, const char *suggestion, bool isOperation) |
| 93 | : ArgumentSuggestioncxx . . $ CppUtilities/ArgumentSuggestion#(unknownArg, unknownArgSize, suggestion, strlen(suggestion), isOperation) |
| 94 | { |
| 95 | } |
| 96 | |
| 97 | bool ArgumentSuggestioncxx . . $ CppUtilities/ArgumentSuggestion#::operatorcxx . . $ CppUtilities/ArgumentSuggestion#`operator<`(c4d65ca16f50c897).<(const ArgumentSuggestioncxx . . $ CppUtilities/ArgumentSuggestion# &other) const |
| 98 | { |
| 99 | return editingDistancecxx . . $ CppUtilities/ArgumentSuggestion#editingDistance. < other.editingDistancecxx . . $ CppUtilities/ArgumentSuggestion#editingDistance.; |
| 100 | } |
| 101 | |
| 102 | void ArgumentSuggestioncxx . . $ CppUtilities/ArgumentSuggestion#::addTocxx . . $ CppUtilities/ArgumentSuggestion#addTo(2da8636ff036a360).(multisetcxx . . $ std/multiset#<ArgumentSuggestioncxx . . $ CppUtilities/ArgumentSuggestion#> &suggestions, size_t limit) const |
| 103 | { |
| 104 | if (suggestions.sizecxx . . $ std/multiset#size(fa801f5ac5d26b4e).() >= limit && !(*this <cxx . . $ CppUtilities/ArgumentSuggestion#`operator<`(c4d65ca16f50c897). *cxx . . $ std/_Rb_tree_const_iterator#`operator*`(2042464fc1fea03e).--cxx . . $ std/_Rb_tree_const_iterator#operator--(9cb79ab07bb244bf).suggestions.endcxx . . $ std/multiset#end(3220b82c0db6d2a1).())) { |
| 105 | return; |
| 106 | } |
| 107 | suggestions.emplacecxx . . $ std/multiset#emplace(e288ee56de383b2).(*this); |
| 108 | while (suggestions.sizecxx . . $ std/multiset#size(fa801f5ac5d26b4e).() > limit) { |
| 109 | suggestions.erasecxx . . $ std/multiset#erase(36a7984e631cd3e9).(--cxx . . $ std/_Rb_tree_const_iterator#operator--(9cb79ab07bb244bf).suggestions.endcxx . . $ std/multiset#end(3220b82c0db6d2a1).()); |
| 110 | } |
| 111 | } |
| 112 | /// \endcond |
| 113 | |
| 114 | /*! |
| 115 | * \class ArgumentReader |
| 116 | * \brief The ArgumentReader class internally encapsulates the process of reading command line arguments. |
| 117 | * \remarks |
| 118 | * - For meaning of parameters see documentation of corresponding member variables. |
| 119 | * - Results are stored in specified \a args and assigned sub arguments. |
| 120 | * - This class is explicitly *not* part of the public API. |
| 121 | */ |
| 122 | |
| 123 | /*! |
| 124 | * \brief Initializes the internal reader for the specified \a parser and arguments. |
| 125 | */ |
| 126 | ArgumentReadercxx . . $ CppUtilities/ArgumentReader#::ArgumentReadercxx . . $ CppUtilities/ArgumentReader#ArgumentReader(5d9014cd7706224b).(ArgumentParsercxx . . $ CppUtilities/ArgumentParser# &parser, const char *const *argv, const char *const *end, bool completionMode) |
| 127 | : parsercxx . . $ CppUtilities/ArgumentReader#parser.(parser) |
| 128 | , argscxx . . $ CppUtilities/ArgumentReader#args.(parser.m_mainArgscxx . . $ CppUtilities/ArgumentParser#m_mainArgs.) |
| 129 | , indexcxx . . $ CppUtilities/ArgumentReader#index.(0) |
| 130 | , argvcxx . . $ CppUtilities/ArgumentReader#argv.(argv) |
| 131 | , endcxx . . $ CppUtilities/ArgumentReader#end.(end) |
| 132 | , lastArgcxx . . $ CppUtilities/ArgumentReader#lastArg.(nullptr) |
| 133 | , argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation.(nullptr) |
| 134 | , completionModecxx . . $ CppUtilities/ArgumentReader#completionMode.(completionMode) |
| 135 | { |
| 136 | } |
| 137 | |
| 138 | /*! |
| 139 | * \brief Resets the ArgumentReader to continue reading new \a argv. |
| 140 | */ |
| 141 | ArgumentReadercxx . . $ CppUtilities/ArgumentReader# &ArgumentReadercxx . . $ CppUtilities/ArgumentReader#::resetcxx . . $ CppUtilities/ArgumentReader#reset(84116d87b2aa3486).(const char *const *argv, const char *const *end) |
| 142 | { |
| 143 | this->argvcxx . . $ CppUtilities/ArgumentReader#argv. = argv; |
| 144 | this->endcxx . . $ CppUtilities/ArgumentReader#end. = end; |
| 145 | indexcxx . . $ CppUtilities/ArgumentReader#index. = 0; |
| 146 | lastArgcxx . . $ CppUtilities/ArgumentReader#lastArg. = nullptr; |
| 147 | argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation. = nullptr; |
| 148 | return *this; |
| 149 | } |
| 150 | |
| 151 | /*! |
| 152 | * \brief Reads the commands line arguments specified when constructing the object. |
| 153 | * \remarks Reads on main-argument-level. |
| 154 | */ |
| 155 | bool ArgumentReadercxx . . $ CppUtilities/ArgumentReader#::readcxx . . $ CppUtilities/ArgumentReader#read(c9857a73d68e59ba).() |
| 156 | { |
| 157 | return readcxx . . $ CppUtilities/ArgumentReader#read(c0f9bd9adf2e50cb).(argscxx . . $ CppUtilities/ArgumentReader#args.); |
| 158 | } |
| 159 | |
| 160 | /*! |
| 161 | * \brief Returns whether the \a denotation with the specified \a denotationLength matches the argument's \a name. |
| 162 | */ |
| 163 | bool Argumentcxx . . $ CppUtilities/Argument#::matchesDenotationcxx . . $ CppUtilities/Argument#matchesDenotation(7d22623725d5361b).(const char *denotation, size_t denotationLength) const |
| 164 | { |
| 165 | return m_namecxx . . $ CppUtilities/Argument#m_name. && !strncmp(m_namecxx . . $ CppUtilities/Argument#m_name., denotation, denotationLength) && *(m_namecxx . . $ CppUtilities/Argument#m_name. + denotationLength) == '\0'; |
| 166 | } |
| 167 | |
| 168 | /*! |
| 169 | * \brief Reads the commands line arguments specified when constructing the object. |
| 170 | * \remarks The argument definitions to look for are specified via \a args. The method calls itself recursively |
| 171 | * to check for nested arguments as well. |
| 172 | * \returns Returns true if all arguments have been processed. Returns false on early exit because some argument |
| 173 | * is unknown and behavior for this case is set to UnknownArgumentBehavior::Fail. |
| 174 | */ |
| 175 | bool ArgumentReadercxx . . $ CppUtilities/ArgumentReader#::readcxx . . $ CppUtilities/ArgumentReader#read(c0f9bd9adf2e50cb).(ArgumentVectorcxx . . $ CppUtilities/ArgumentVector# &args) |
| 176 | { |
| 177 | // method is called recursively for sub args to the last argument (which is nullptr in the initial call) is the current parent argument |
| 178 | Argumentcxx . . $ CppUtilities/Argument# *const parentArg = lastArgcxx . . $ CppUtilities/ArgumentReader#lastArg.; |
| 179 | // determine the current path |
| 180 | const vectorcxx . . $ std/vector#<Argumentcxx . . $ CppUtilities/Argument# *> &parentPath = parentArg ? parentArgcxx . . $ std/vector#vector(a1201200cf0efa42).->pathcxx . . $ CppUtilities/Argument#path(b87142e1c5eb1796).(parentArg->occurrencescxx . . $ CppUtilities/Argument#occurrences(fe4d2d262d4164a8).() - 1) : vectorcxx . . $ std/vector#vector(49f6e7a06ebc5aa8).<Argumentcxx . . $ CppUtilities/Argument# *>(); |
| 181 | |
| 182 | Argumentcxx . . $ CppUtilities/Argument# *lastArgInLevel = nullptr; |
| 183 | vectorcxx . . $ std/vector#<const char *> *values = nullptr; |
| 184 | |
| 185 | // iterate through all argument denotations; loop might exit earlier when a denotation is unknown |
| 186 | while (argvcxx . . $ CppUtilities/ArgumentReader#argv. != endcxx . . $ CppUtilities/ArgumentReader#end.) { |
| 187 | // check whether there are still values to read |
| 188 | if (values && ((lastArgInLevel->requiredValueCountcxx . . $ CppUtilities/Argument#requiredValueCount(fe4d2d262d4164a8).() != Argumentcxx . . $ CppUtilities/Argument#::varValueCountcxx . . $ CppUtilities/Argument#varValueCount.) || (lastArgInLevel->flagscxx . . $ CppUtilities/Argument#flags(17c623cd32e8f2b8).() &cxx . . $ CppUtilities/`operator&`(564b1b0111016947). Argumentcxx . . $ CppUtilities/Argument#::Flagscxx . . $ CppUtilities/Argument#Flags#::Greedycxx . . $ CppUtilities/Argument#Flags#Greedy.)) |
| 189 | && values->sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() < lastArgInLevel->requiredValueCountcxx . . $ CppUtilities/Argument#requiredValueCount(fe4d2d262d4164a8).()) { |
| 190 | // read arg as value and continue with next arg |
| 191 | values->emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation. ? argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation. : *argvcxx . . $ CppUtilities/ArgumentReader#argv.); |
| 192 | ++indexcxx . . $ CppUtilities/ArgumentReader#index.; |
| 193 | ++argvcxx . . $ CppUtilities/ArgumentReader#argv.; |
| 194 | argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation. = nullptr; |
| 195 | continue; |
| 196 | } |
| 197 | |
| 198 | // determine how denotation must be processed |
| 199 | bool abbreviationFound = false; |
| 200 | if (argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation.) { |
| 201 | // continue reading children for abbreviation denotation already detected |
| 202 | abbreviationFound = false; |
| 203 | argDenotationTypecxx . . $ CppUtilities/ArgumentReader#argDenotationType. = Abbreviationcxx . . $ CppUtilities/Abbreviation.; |
| 204 | } else { |
| 205 | // determine denotation type |
| 206 | argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation. = *argvcxx . . $ CppUtilities/ArgumentReader#argv.; |
| 207 | if (!*argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation. && (!lastArgInLevel || values->sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() >= lastArgInLevel->requiredValueCountcxx . . $ CppUtilities/Argument#requiredValueCount(fe4d2d262d4164a8).())) { |
| 208 | // skip empty arguments |
| 209 | ++indexcxx . . $ CppUtilities/ArgumentReader#index.; |
| 210 | ++argvcxx . . $ CppUtilities/ArgumentReader#argv.; |
| 211 | argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation. = nullptr; |
| 212 | continue; |
| 213 | } |
| 214 | abbreviationFound = false; |
| 215 | argDenotationTypecxx . . $ CppUtilities/ArgumentReader#argDenotationType. = Valuecxx . . $ CppUtilities/Value.; |
| 216 | if (*argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation. == '-') { |
| 217 | ++argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation.; |
| 218 | ++argDenotationTypecxx . . $ CppUtilities/ArgumentReader#argDenotationType.; |
| 219 | if (*argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation. == '-') { |
| 220 | ++argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation.; |
| 221 | ++argDenotationTypecxx . . $ CppUtilities/ArgumentReader#argDenotationType.; |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | // try to find matching Argument instance |
| 227 | Argumentcxx . . $ CppUtilities/Argument# *matchingArg = nullptr; |
| 228 | if (argDenotationTypecxx . . $ CppUtilities/ArgumentReader#argDenotationType. != Valuecxx . . $ CppUtilities/Value.) { |
| 229 | // determine actual denotation length (everything before equation sign) |
| 230 | const char *const equationPos = strchr(argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation., '='); |
| 231 | const auto argDenotationLength = equationPos ? static_cast<size_t>(equationPos - argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation.) : strlen(argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation.); |
| 232 | |
| 233 | // loop through each "part" of the denotation |
| 234 | // names are read at once, but for abbreviations each character is considered individually |
| 235 | for (; argDenotationLength; matchingArg = nullptr) { |
| 236 | // search for arguments by abbreviation or name depending on the previously determined denotation type |
| 237 | if (argDenotationTypecxx . . $ CppUtilities/ArgumentReader#argDenotationType. == Abbreviationcxx . . $ CppUtilities/Abbreviation.) { |
| 238 | for (Argumentcxx . . $ CppUtilities/Argument# *const arg : args) { |
| 239 | if (arg->abbreviationcxx . . $ CppUtilities/Argument#abbreviation(1b8b762cbef9c2c9).() && arg->abbreviationcxx . . $ CppUtilities/Argument#abbreviation(1b8b762cbef9c2c9).() == *argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation.) { |
| 240 | matchingArg = arg; |
| 241 | abbreviationFound = true; |
| 242 | break; |
| 243 | } |
| 244 | } |
| 245 | } else { |
| 246 | for (Argumentcxx . . $ CppUtilities/Argument# *const arg : args) { |
| 247 | if (arg->matchesDenotationcxx . . $ CppUtilities/Argument#matchesDenotation(7d22623725d5361b).(argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation., argDenotationLength)) { |
| 248 | matchingArg = arg; |
| 249 | break; |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | if (!matchingArg) { |
| 254 | break; |
| 255 | } |
| 256 | |
| 257 | // an argument matched the specified denotation so add an occurrence |
| 258 | matchingArg->m_occurrencescxx . . $ CppUtilities/Argument#m_occurrences..emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(indexcxx . . $ CppUtilities/ArgumentReader#index., parentPath, parentArg); |
| 259 | |
| 260 | // prepare reading parameter values |
| 261 | values = &matchingArg->m_occurrencescxx . . $ CppUtilities/Argument#m_occurrences..backcxx . . $ std/vector#back(6baabfa6fc7b3a8e).().valuescxx . . $ CppUtilities/ArgumentOccurrence#values.; |
| 262 | |
| 263 | // read value after equation sign |
| 264 | if ((argDenotationTypecxx . . $ CppUtilities/ArgumentReader#argDenotationType. != Abbreviationcxx . . $ CppUtilities/Abbreviation. && equationPos) || (++argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation. == equationPos)) { |
| 265 | values->push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(equationPos + 1); |
| 266 | argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation. = nullptr; |
| 267 | } |
| 268 | |
| 269 | // read sub arguments, distinguish whether further abbreviations follow |
| 270 | ++indexcxx . . $ CppUtilities/ArgumentReader#index.; |
| 271 | ++parsercxx . . $ CppUtilities/ArgumentReader#parser..m_actualArgccxx . . $ CppUtilities/ArgumentParser#m_actualArgc.; |
| 272 | lastArgcxx . . $ CppUtilities/ArgumentReader#lastArg. = lastArgInLevel = matchingArg; |
| 273 | lastArgDenotationcxx . . $ CppUtilities/ArgumentReader#lastArgDenotation. = argvcxx . . $ CppUtilities/ArgumentReader#argv.; |
| 274 | if (argDenotationTypecxx . . $ CppUtilities/ArgumentReader#argDenotationType. != Abbreviationcxx . . $ CppUtilities/Abbreviation. || !argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation. || !*argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation.) { |
| 275 | // no further abbreviations follow -> read sub args for next argv |
| 276 | ++argvcxx . . $ CppUtilities/ArgumentReader#argv.; |
| 277 | argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation. = nullptr; |
| 278 | readcxx . . $ CppUtilities/ArgumentReader#read(c0f9bd9adf2e50cb).(lastArgcxx . . $ CppUtilities/ArgumentReader#lastArg.->m_subArgscxx . . $ CppUtilities/Argument#m_subArgs.); |
| 279 | argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation. = nullptr; |
| 280 | break; |
| 281 | } else { |
| 282 | // further abbreviations follow -> remember current arg value |
| 283 | const char *const *const currentArgValue = argvcxx . . $ CppUtilities/ArgumentReader#argv.; |
| 284 | // don't increment argv, keep processing outstanding chars of argDenotation |
| 285 | readcxx . . $ CppUtilities/ArgumentReader#read(c0f9bd9adf2e50cb).(lastArgcxx . . $ CppUtilities/ArgumentReader#lastArg.->m_subArgscxx . . $ CppUtilities/Argument#m_subArgs.); |
| 286 | // stop further processing if the denotation has been consumed or even the next value has already been loaded |
| 287 | if (!argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation. || currentArgValue != argvcxx . . $ CppUtilities/ArgumentReader#argv.) { |
| 288 | argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation. = nullptr; |
| 289 | break; |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | // continue with next arg if we've got a match already |
| 295 | if (matchingArg) { |
| 296 | continue; |
| 297 | } |
| 298 | |
| 299 | // unknown argument might be a sibling of the parent element |
| 300 | for (auto parentArgument = parentPath.crbegincxx . . $ std/vector#crbegin(7ffd9c4e53ea04dd).(), pathEnd = parentPath.crendcxx . . $ std/vector#crend(7ffd9c4e53ea04dd).();; ++cxx . . $ std/reverse_iterator#operator++(b4fad7494eaaab68).parentArgument) { |
| 301 | for (Argumentcxx . . $ CppUtilities/Argument# *const sibling : (parentArgument !=cxx . . $ std/`operator!=`(c2ad8cf295ccec45). pathEnd ? (*cxx . . $ std/reverse_iterator#`operator*`(c076846f881f3e7e).parentArgument)->subArgumentscxx . . $ CppUtilities/Argument#subArguments(1ef3bc1254d64c10).() : parsercxx . . $ CppUtilities/ArgumentReader#parser..m_mainArgscxx . . $ CppUtilities/ArgumentParser#m_mainArgs.)) { |
| 302 | if (sibling->occurrencescxx . . $ CppUtilities/Argument#occurrences(fe4d2d262d4164a8).() < sibling->maxOccurrencescxx . . $ CppUtilities/Argument#maxOccurrences(fe4d2d262d4164a8).()) { |
| 303 | // check whether the denoted abbreviation matches the sibling's abbreviatiopn |
| 304 | if (argDenotationTypecxx . . $ CppUtilities/ArgumentReader#argDenotationType. == Abbreviationcxx . . $ CppUtilities/Abbreviation. && (sibling->abbreviationcxx . . $ CppUtilities/Argument#abbreviation(1b8b762cbef9c2c9).() && sibling->abbreviationcxx . . $ CppUtilities/Argument#abbreviation(1b8b762cbef9c2c9).() == *argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation.)) { |
| 305 | return false; |
| 306 | } |
| 307 | // check whether the denoted name matches the sibling's name |
| 308 | if (sibling->matchesDenotationcxx . . $ CppUtilities/Argument#matchesDenotation(7d22623725d5361b).(argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation., argDenotationLength)) { |
| 309 | return false; |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | if (parentArgument ==cxx . . $ std/`operator==`(c2ad8cf295ccec45). pathEnd) { |
| 314 | break; |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | // unknown argument might just be a parameter value of the last argument |
| 320 | if (lastArgInLevel && values->sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() < lastArgInLevel->requiredValueCountcxx . . $ CppUtilities/Argument#requiredValueCount(fe4d2d262d4164a8).()) { |
| 321 | values->emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(abbreviationFound ? argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation. : *argvcxx . . $ CppUtilities/ArgumentReader#argv.); |
| 322 | ++indexcxx . . $ CppUtilities/ArgumentReader#index.; |
| 323 | ++argvcxx . . $ CppUtilities/ArgumentReader#argv.; |
| 324 | argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation. = nullptr; |
| 325 | continue; |
| 326 | } |
| 327 | |
| 328 | // first value might denote "operation" |
| 329 | for (Argumentcxx . . $ CppUtilities/Argument# *const arg : args) { |
| 330 | if (arg->denotesOperationcxx . . $ CppUtilities/Argument#denotesOperation(50ce9a9e25b4a850).() && arg->namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).() && !strcmp(arg->namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).(), *argvcxx . . $ CppUtilities/ArgumentReader#argv.)) { |
| 331 | (matchingArg = arg)->m_occurrencescxx . . $ CppUtilities/Argument#m_occurrences..emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(indexcxx . . $ CppUtilities/ArgumentReader#index., parentPath, parentArg); |
| 332 | lastArgDenotationcxx . . $ CppUtilities/ArgumentReader#lastArgDenotation. = argvcxx . . $ CppUtilities/ArgumentReader#argv.; |
| 333 | ++indexcxx . . $ CppUtilities/ArgumentReader#index.; |
| 334 | ++argvcxx . . $ CppUtilities/ArgumentReader#argv.; |
| 335 | break; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | // use the first default argument which is not already present if there is still no match |
| 340 | if (!matchingArg && (!completionModecxx . . $ CppUtilities/ArgumentReader#completionMode. || (argvcxx . . $ CppUtilities/ArgumentReader#argv. + 1 != endcxx . . $ CppUtilities/ArgumentReader#end.))) { |
| 341 | const bool uncombinableMainArgPresent = parentArg ? false : parsercxx . . $ CppUtilities/ArgumentReader#parser..isUncombinableMainArgPresentcxx . . $ CppUtilities/ArgumentParser#isUncombinableMainArgPresent(50ce9a9e25b4a850).(); |
| 342 | for (Argumentcxx . . $ CppUtilities/Argument# *const arg : args) { |
| 343 | if (arg->isImplicitcxx . . $ CppUtilities/Argument#isImplicit(50ce9a9e25b4a850).() && !arg->isPresentcxx . . $ CppUtilities/Argument#isPresent(50ce9a9e25b4a850).() && !arg->wouldConflictWithArgumentcxx . . $ CppUtilities/Argument#wouldConflictWithArgument(cb6a3fc127670316).() |
| 344 | && (!uncombinableMainArgPresent || !arg->isMainArgumentcxx . . $ CppUtilities/Argument#isMainArgument(50ce9a9e25b4a850).())) { |
| 345 | (matchingArg = arg)->m_occurrencescxx . . $ CppUtilities/Argument#m_occurrences..emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(indexcxx . . $ CppUtilities/ArgumentReader#index., parentPath, parentArg); |
| 346 | break; |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | if (matchingArg) { |
| 352 | // an argument matched the specified denotation |
| 353 | if (lastArgInLevel == matchingArg) { |
| 354 | break; // break required? -> TODO: add test for this condition |
| 355 | } |
| 356 | |
| 357 | // prepare reading parameter values |
| 358 | values = &matchingArg->m_occurrencescxx . . $ CppUtilities/Argument#m_occurrences..backcxx . . $ std/vector#back(6baabfa6fc7b3a8e).().valuescxx . . $ CppUtilities/ArgumentOccurrence#values.; |
| 359 | |
| 360 | // read sub arguments |
| 361 | ++parsercxx . . $ CppUtilities/ArgumentReader#parser..m_actualArgccxx . . $ CppUtilities/ArgumentParser#m_actualArgc.; |
| 362 | lastArgcxx . . $ CppUtilities/ArgumentReader#lastArg. = lastArgInLevel = matchingArg; |
| 363 | argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation. = nullptr; |
| 364 | if ((values->sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() < matchingArg->requiredValueCountcxx . . $ CppUtilities/Argument#requiredValueCount(fe4d2d262d4164a8).()) && (matchingArg->flagscxx . . $ CppUtilities/Argument#flags(17c623cd32e8f2b8).() &cxx . . $ CppUtilities/`operator&`(564b1b0111016947). Argumentcxx . . $ CppUtilities/Argument#::Flagscxx . . $ CppUtilities/Argument#Flags#::Greedycxx . . $ CppUtilities/Argument#Flags#Greedy.)) { |
| 365 | continue; |
| 366 | } |
| 367 | readcxx . . $ CppUtilities/ArgumentReader#read(c0f9bd9adf2e50cb).(lastArgcxx . . $ CppUtilities/ArgumentReader#lastArg.->m_subArgscxx . . $ CppUtilities/Argument#m_subArgs.); |
| 368 | argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation. = nullptr; |
| 369 | continue; |
| 370 | } |
| 371 | |
| 372 | // argument denotation is unknown -> handle error |
| 373 | if (parentArg) { |
| 374 | // continue with parent level |
| 375 | return false; |
| 376 | } |
| 377 | if (completionModecxx . . $ CppUtilities/ArgumentReader#completionMode.) { |
| 378 | // ignore unknown denotation |
| 379 | ++indexcxx . . $ CppUtilities/ArgumentReader#index.; |
| 380 | ++argvcxx . . $ CppUtilities/ArgumentReader#argv.; |
| 381 | argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation. = nullptr; |
| 382 | } else { |
| 383 | switch (parsercxx . . $ CppUtilities/ArgumentReader#parser..m_unknownArgBehaviorcxx . . $ CppUtilities/ArgumentParser#m_unknownArgBehavior.) { |
| 384 | case UnknownArgumentBehaviorcxx . . $ CppUtilities/UnknownArgumentBehavior#::Warncxx . . $ CppUtilities/UnknownArgumentBehavior#Warn.: |
| 385 | cerrcxx . . $ std/cerr. <<cxx . . $ CppUtilities/EscapeCodes/`operator<<`(75f7075e21abbe9a). Phrasescxx . . $ CppUtilities/EscapeCodes/Phrases#::Warningcxx . . $ CppUtilities/EscapeCodes/Phrases#Warning. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "The specified argument \"" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). *argvcxx . . $ CppUtilities/ArgumentReader#argv. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\" is unknown and will be ignored." <<cxx . . $ CppUtilities/EscapeCodes/`operator<<`(75f7075e21abbe9a). Phrasescxx . . $ CppUtilities/EscapeCodes/Phrases#::EndFlushcxx . . $ CppUtilities/EscapeCodes/Phrases#EndFlush.; |
| 386 | [[fallthrough]]; |
| 387 | case UnknownArgumentBehaviorcxx . . $ CppUtilities/UnknownArgumentBehavior#::Ignorecxx . . $ CppUtilities/UnknownArgumentBehavior#Ignore.: |
| 388 | // ignore unknown denotation |
| 389 | ++indexcxx . . $ CppUtilities/ArgumentReader#index.; |
| 390 | ++argvcxx . . $ CppUtilities/ArgumentReader#argv.; |
| 391 | argDenotationcxx . . $ CppUtilities/ArgumentReader#argDenotation. = nullptr; |
| 392 | break; |
| 393 | case UnknownArgumentBehaviorcxx . . $ CppUtilities/UnknownArgumentBehavior#::Failcxx . . $ CppUtilities/UnknownArgumentBehavior#Fail.: |
| 394 | return false; |
| 395 | } |
| 396 | } |
| 397 | } // while(argv != end) |
| 398 | return true; |
| 399 | } |
| 400 | |
| 401 | /*! |
| 402 | * \class Wrapper |
| 403 | * \brief The Wrapper class is internally used print text which might needs to be wrapped preserving the indentation. |
| 404 | * \remarks This class is explicitly *not* part of the public API. |
| 405 | */ |
| 406 | |
| 407 | ostreamcxx . . $ std/ostream# &operatorcxx . . $ CppUtilities/`operator<<`(eb72771242142f3a).<<(ostreamcxx . . $ std/ostream# &os, const Wrappercxx . . $ CppUtilities/Wrapper# &wrapper) |
| 408 | { |
| 409 | // determine max. number of columns |
| 410 | static const TerminalSizecxx . . $ CppUtilities/TerminalSize# termSize(determineTerminalSizecxx . . $ CppUtilities/determineTerminalSize(606d4e856e7d8688).()); |
| 411 | const auto maxColumns = termSize.columnscxx . . $ CppUtilities/TerminalSize#columns. ? termSize.columnscxx . . $ CppUtilities/TerminalSize#columns. : numeric_limitscxx . . $ std/numeric_limits#<unsigned short>::maxcxx . . $ std/numeric_limits#max(ab96d7673181286b).(); |
| 412 | |
| 413 | // print wrapped string considering indentation |
| 414 | unsigned short currentCol = wrapper.m_indentationcxx . . $ CppUtilities/Wrapper#m_indentation..levelcxx . . $ CppUtilities/Indentation#level.; |
| 415 | for (const char *currentChar = wrapper.m_strcxx . . $ CppUtilities/Wrapper#m_str.; *currentChar; ++currentChar) { |
| 416 | const bool wrappingRequired = currentCol >= maxColumns; |
| 417 | if (wrappingRequired || *currentChar == '\n') { |
| 418 | // insert newline (TODO: wrap only at end of a word) |
| 419 | os <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\n'; |
| 420 | // print indentation (if enough space) |
| 421 | if (wrapper.m_indentationcxx . . $ CppUtilities/Wrapper#m_indentation..levelcxx . . $ CppUtilities/Indentation#level. < maxColumns) { |
| 422 | os <<cxx . . $ CppUtilities/`operator<<`(9f925d273f9b84d1). wrapper.m_indentationcxx . . $ CppUtilities/Wrapper#m_indentation.; |
| 423 | currentCol = wrapper.m_indentationcxx . . $ CppUtilities/Wrapper#m_indentation..levelcxx . . $ CppUtilities/Indentation#level.; |
| 424 | } else { |
| 425 | currentCol = 0; |
| 426 | } |
| 427 | } |
| 428 | if (*currentChar != '\n' && (!wrappingRequired || *currentChar != ' ')) { |
| 429 | os <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). *currentChar; |
| 430 | ++currentCol; |
| 431 | } |
| 432 | } |
| 433 | return os; |
| 434 | } |
| 435 | |
| 436 | CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! ApplicationInfocxx . . $ CppUtilities/ApplicationInfo# applicationInfocxx . . $ CppUtilities/applicationInfo.; |
| 437 | |
| 438 | /// \cond |
| 439 | |
| 440 | inline bool notEmptycxx . . $ CppUtilities/notEmpty(c5f7da30cbc0f4e9).(const char *str) |
| 441 | { |
| 442 | return str && *str; |
| 443 | } |
| 444 | |
| 445 | /// \endcond |
| 446 | |
| 447 | /*! |
| 448 | * \class Argument |
| 449 | * \brief The Argument class is a wrapper for command line argument information. |
| 450 | * |
| 451 | * Instances of the Argument class are used as definition when parsing command line |
| 452 | * arguments. Arguments can be assigned to an ArgumentParser using |
| 453 | * ArgumentParser::setMainArguments() and to another Argument instance using |
| 454 | * Argument::setSubArguments(). |
| 455 | */ |
| 456 | |
| 457 | /*! |
| 458 | * \brief Constructs an Argument with the given \a name, \a abbreviation and \a description. |
| 459 | * |
| 460 | * The \a name and the abbreviation mustn't contain any whitespaces. |
| 461 | * The \a name mustn't be empty. The \a abbreviation and the \a description might be empty. |
| 462 | */ |
| 463 | Argumentcxx . . $ CppUtilities/Argument#::Argumentcxx . . $ CppUtilities/Argument#Argument(af3d03003c91f516).(const char *name, char abbreviation, const char *description, const char *example) |
| 464 | : m_namecxx . . $ CppUtilities/Argument#m_name.(name) |
| 465 | , m_abbreviationcxx . . $ CppUtilities/Argument#m_abbreviation.(abbreviation) |
| 466 | , m_environmentVarcxx . . $ CppUtilities/Argument#m_environmentVar.(nullptr) |
| 467 | , m_descriptioncxx . . $ CppUtilities/Argument#m_description.(description) |
| 468 | , m_examplecxx . . $ CppUtilities/Argument#m_example.(example) |
| 469 | , m_minOccurrencescxx . . $ CppUtilities/Argument#m_minOccurrences.(0) |
| 470 | , m_maxOccurrencescxx . . $ CppUtilities/Argument#m_maxOccurrences.(1) |
| 471 | , m_requiredValueCountcxx . . $ CppUtilities/Argument#m_requiredValueCount.(0) |
| 472 | , m_flagscxx . . $ CppUtilities/Argument#m_flags.(Flagscxx . . $ CppUtilities/Argument#Flags#::Nonecxx . . $ CppUtilities/Argument#Flags#None.) |
| 473 | , m_deprecatedBycxx . . $ CppUtilities/Argument#m_deprecatedBy.(nullptr) |
| 474 | , m_isMainArgcxx . . $ CppUtilities/Argument#m_isMainArg.(false) |
| 475 | , m_valueCompletionBehaviorcxx . . $ CppUtilities/Argument#m_valueCompletionBehavior.(ValueCompletionBehaviorcxx . . $ CppUtilities/ValueCompletionBehavior#::PreDefinedValuescxx . . $ CppUtilities/ValueCompletionBehavior#PreDefinedValues. |cxx . . $ CppUtilities/`operator|`(c2b922020561bbb). ValueCompletionBehaviorcxx . . $ CppUtilities/ValueCompletionBehavior#::Filescxx . . $ CppUtilities/ValueCompletionBehavior#Files. |cxx . . $ CppUtilities/`operator|`(c2b922020561bbb). ValueCompletionBehaviorcxx . . $ CppUtilities/ValueCompletionBehavior#::Directoriescxx . . $ CppUtilities/ValueCompletionBehavior#Directories. |
| 476 | |cxx . . $ CppUtilities/`operator|`(c2b922020561bbb). ValueCompletionBehaviorcxx . . $ CppUtilities/ValueCompletionBehavior#::FileSystemIfNoPreDefinedValuescxx . . $ CppUtilities/ValueCompletionBehavior#FileSystemIfNoPreDefinedValues.) |
| 477 | , m_preDefinedCompletionValuescxx . . $ CppUtilities/Argument#m_preDefinedCompletionValues.(nullptr) |
| 478 | { |
| 479 | } |
| 480 | |
| 481 | /*! |
| 482 | * \brief Destroys the Argument. |
| 483 | */ |
| 484 | Argumentcxx . . $ CppUtilities/Argument#::~cxx . . $ CppUtilities/Argument#`~Argument`(ced63f7c635d850d).Argumentcxx . . $ CppUtilities/Argument#() |
| 485 | { |
| 486 | } |
| 487 | |
| 488 | /*! |
| 489 | * \brief Returns the first parameter value of the first occurrence of the argument. |
| 490 | * \remarks |
| 491 | * - If the argument is not present and the an environment variable has been set |
| 492 | * using setEnvironmentVariable() the value of the specified variable will be returned. |
| 493 | * - Returns nullptr if no value is available though. |
| 494 | */ |
| 495 | const char *Argumentcxx . . $ CppUtilities/Argument#::firstValuecxx . . $ CppUtilities/Argument#firstValue(a9f41ea0e82d88cf).() const |
| 496 | { |
| 497 | if (!m_occurrencescxx . . $ CppUtilities/Argument#m_occurrences..emptycxx . . $ std/vector#empty(3482b152b9333168).() && !m_occurrencescxx . . $ CppUtilities/Argument#m_occurrences..frontcxx . . $ std/vector#front(af0004c3ce7cab93).().valuescxx . . $ CppUtilities/ArgumentOccurrence#values..emptycxx . . $ std/vector#empty(3482b152b9333168).()) { |
| 498 | return m_occurrencescxx . . $ CppUtilities/Argument#m_occurrences..frontcxx . . $ std/vector#front(af0004c3ce7cab93).().valuescxx . . $ CppUtilities/ArgumentOccurrence#values..frontcxx . . $ std/vector#front(af0004c3ce7cab93).(); |
| 499 | } else if (m_environmentVarcxx . . $ CppUtilities/Argument#m_environmentVar.) { |
| 500 | return getenv(m_environmentVarcxx . . $ CppUtilities/Argument#m_environmentVar.); |
| 501 | } else { |
| 502 | return nullptr; |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | /*! |
| 507 | * \brief Returns the first value like Argument::firstValue() but returns \a fallback instead of nullptr if there's no value. |
| 508 | */ |
| 509 | const char *Argumentcxx . . $ CppUtilities/Argument#::firstValueOrcxx . . $ CppUtilities/Argument#firstValueOr(865ea18671f48fc1).(const char *fallback) const |
| 510 | { |
| 511 | if (const auto *const v = firstValuecxx . . $ CppUtilities/Argument#firstValue(a9f41ea0e82d88cf).()) { |
| 512 | return v; |
| 513 | } else { |
| 514 | return fallback; |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | /*! |
| 519 | * \brief Writes the name, the abbreviation and other information about the Argument to the give ostream. |
| 520 | */ |
| 521 | void Argumentcxx . . $ CppUtilities/Argument#::printInfocxx . . $ CppUtilities/Argument#printInfo(26c0a26698046a31).(ostreamcxx . . $ std/ostream# &os, unsigned char indentation) const |
| 522 | { |
| 523 | if (isDeprecatedcxx . . $ CppUtilities/Argument#isDeprecated(50ce9a9e25b4a850).()) { |
| 524 | return; |
| 525 | } |
| 526 | Indentationcxx . . $ CppUtilities/Indentation# identcxx . . $ CppUtilities/Indentation#Indentation(bf39ed7cbaca7ebc).(indentation); |
| 527 | os <<cxx . . $ CppUtilities/`operator<<`(9f925d273f9b84d1). ident; |
| 528 | EscapeCodescxx . . $ CppUtilities/EscapeCodes/::setStylecxx . . $ CppUtilities/EscapeCodes/setStyle(347736b94b25c94c).(os, EscapeCodescxx . . $ CppUtilities/EscapeCodes/::TextAttributecxx . . $ CppUtilities/EscapeCodes/TextAttribute#::Boldcxx . . $ CppUtilities/EscapeCodes/TextAttribute#Bold.); |
| 529 | if (notEmptycxx . . $ CppUtilities/notEmpty(c5f7da30cbc0f4e9).(namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).())) { |
| 530 | if (!denotesOperationcxx . . $ CppUtilities/Argument#denotesOperation(50ce9a9e25b4a850).()) { |
| 531 | os <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '-' <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '-'; |
| 532 | } |
| 533 | os <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).(); |
| 534 | } |
| 535 | if (notEmptycxx . . $ CppUtilities/notEmpty(c5f7da30cbc0f4e9).(namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).()) && abbreviationcxx . . $ CppUtilities/Argument#abbreviation(1b8b762cbef9c2c9).()) { |
| 536 | os <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ',' <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' '; |
| 537 | } |
| 538 | if (abbreviationcxx . . $ CppUtilities/Argument#abbreviation(1b8b762cbef9c2c9).()) { |
| 539 | os <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '-' <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). abbreviationcxx . . $ CppUtilities/Argument#abbreviation(1b8b762cbef9c2c9).(); |
| 540 | } |
| 541 | EscapeCodescxx . . $ CppUtilities/EscapeCodes/::setStylecxx . . $ CppUtilities/EscapeCodes/setStyle(347736b94b25c94c).(os); |
| 542 | if (requiredValueCountcxx . . $ CppUtilities/Argument#requiredValueCount(fe4d2d262d4164a8).()) { |
| 543 | unsigned int valueNamesPrint = 0; |
| 544 | for (auto i = valueNamescxx . . $ CppUtilities/Argument#valueNames(6073f6567d110ada).().cbegincxx . . $ std/vector#cbegin(d1e1699016b9d7e6).(), end = valueNamescxx . . $ CppUtilities/Argument#valueNames(6073f6567d110ada).().cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).(); i !=cxx . . $ __gnu_cxx/`operator!=`(30ee64f2df4eef8b). end && valueNamesPrint < requiredValueCountcxx . . $ CppUtilities/Argument#requiredValueCount(fe4d2d262d4164a8).(); ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(1613faa01bc3d014).i) { |
| 545 | os <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '[' <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).i <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ']'; |
| 546 | ++valueNamesPrint; |
| 547 | } |
| 548 | if (requiredValueCountcxx . . $ CppUtilities/Argument#requiredValueCount(fe4d2d262d4164a8).() == Argumentcxx . . $ CppUtilities/Argument#::varValueCountcxx . . $ CppUtilities/Argument#varValueCount.) { |
| 549 | os <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " ..."; |
| 550 | } else { |
| 551 | for (; valueNamesPrint < requiredValueCountcxx . . $ CppUtilities/Argument#requiredValueCount(fe4d2d262d4164a8).(); ++valueNamesPrint) { |
| 552 | os <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " [value " <<cxx . . $ std/basic_ostream#`operator<<`(b4c055c363850233). (valueNamesPrint + 1) <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ']'; |
| 553 | } |
| 554 | } |
| 555 | } |
| 556 | ident.levelcxx . . $ CppUtilities/Indentation#level. += 2; |
| 557 | if (notEmptycxx . . $ CppUtilities/notEmpty(c5f7da30cbc0f4e9).(descriptioncxx . . $ CppUtilities/Argument#description(a9f41ea0e82d88cf).())) { |
| 558 | os <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\n' <<cxx . . $ CppUtilities/`operator<<`(9f925d273f9b84d1). ident <<cxx . . $ CppUtilities/`operator<<`(eb72771242142f3a). Wrappercxx . . $ CppUtilities/Wrapper#Wrapper(e9c43e74416273b7).(descriptioncxx . . $ CppUtilities/Argument#description(a9f41ea0e82d88cf).(), ident); |
| 559 | } |
| 560 | if (isRequiredcxx . . $ CppUtilities/Argument#isRequired(50ce9a9e25b4a850).()) { |
| 561 | os <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\n' <<cxx . . $ CppUtilities/`operator<<`(9f925d273f9b84d1). ident <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "particularities: mandatory"; |
| 562 | if (!isMainArgumentcxx . . $ CppUtilities/Argument#isMainArgument(50ce9a9e25b4a850).()) { |
| 563 | os <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " if parent argument is present"; |
| 564 | } |
| 565 | } |
| 566 | if (environmentVariablecxx . . $ CppUtilities/Argument#environmentVariable(a9f41ea0e82d88cf).()) { |
| 567 | os <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\n' <<cxx . . $ CppUtilities/`operator<<`(9f925d273f9b84d1). ident <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "default environment variable: " <<cxx . . $ CppUtilities/`operator<<`(eb72771242142f3a). Wrappercxx . . $ CppUtilities/Wrapper#Wrapper(e9c43e74416273b7).(environmentVariablecxx . . $ CppUtilities/Argument#environmentVariable(a9f41ea0e82d88cf).(), ident +cxx . . $ CppUtilities/Indentation#operator+(e2d219d5a0430609). 30); |
| 568 | } |
| 569 | os <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\n'; |
| 570 | bool hasSubArgs = false; |
| 571 | for (const auto *const arg : subArgumentscxx . . $ CppUtilities/Argument#subArguments(1ef3bc1254d64c10).()) { |
| 572 | if (arg->isDeprecatedcxx . . $ CppUtilities/Argument#isDeprecated(50ce9a9e25b4a850).()) { |
| 573 | continue; |
| 574 | } |
| 575 | hasSubArgs = true; |
| 576 | arg->printInfocxx . . $ CppUtilities/Argument#printInfo(26c0a26698046a31).(os, ident.levelcxx . . $ CppUtilities/Indentation#level.); |
| 577 | } |
| 578 | if (notEmptycxx . . $ CppUtilities/notEmpty(c5f7da30cbc0f4e9).(examplecxx . . $ CppUtilities/Argument#example(a9f41ea0e82d88cf).())) { |
| 579 | if (ident.levelcxx . . $ CppUtilities/Indentation#level. == 2 && hasSubArgs) { |
| 580 | os <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\n'; |
| 581 | } |
| 582 | os <<cxx . . $ CppUtilities/`operator<<`(9f925d273f9b84d1). ident <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "example: " <<cxx . . $ CppUtilities/`operator<<`(eb72771242142f3a). Wrappercxx . . $ CppUtilities/Wrapper#Wrapper(e9c43e74416273b7).(examplecxx . . $ CppUtilities/Argument#example(a9f41ea0e82d88cf).(), ident +cxx . . $ CppUtilities/Indentation#operator+(e2d219d5a0430609). 9); |
| 583 | os <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\n'; |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | /*! |
| 588 | * \brief This function return the first present and uncombinable argument of the given list of arguments. |
| 589 | * |
| 590 | * The Argument \a except will be ignored. |
| 591 | */ |
| 592 | Argumentcxx . . $ CppUtilities/Argument# *firstPresentUncombinableArgcxx . . $ CppUtilities/firstPresentUncombinableArg(90bfa07d5099c83e).(const ArgumentVectorcxx . . $ CppUtilities/ArgumentVector# &args, const Argumentcxx . . $ CppUtilities/Argument# *except) |
| 593 | { |
| 594 | for (Argumentcxx . . $ CppUtilities/Argument# *arg : args) { |
| 595 | if (arg != except && arg->isPresentcxx . . $ CppUtilities/Argument#isPresent(50ce9a9e25b4a850).() && !arg->isCombinablecxx . . $ CppUtilities/Argument#isCombinable(50ce9a9e25b4a850).()) { |
| 596 | return arg; |
| 597 | } |
| 598 | } |
| 599 | return nullptr; |
| 600 | } |
| 601 | |
| 602 | /*! |
| 603 | * \brief Sets the secondary arguments for this argument. |
| 604 | * |
| 605 | * The given arguments will be considered as secondary arguments of this argument by the argument parser. |
| 606 | * This means that the parser will complain if these arguments are given, but not this argument. |
| 607 | * If secondary arguments are labeled as mandatory their parent is also mandatory. |
| 608 | * |
| 609 | * The Argument does not take ownership. Do not destroy the given arguments as long as they are |
| 610 | * used as secondary arguments. |
| 611 | * |
| 612 | * \sa addSubArguments() |
| 613 | * \sa secondaryArguments() |
| 614 | * \sa addSecondaryArgument() |
| 615 | * \sa hasSubArguments() |
| 616 | */ |
| 617 | void Argumentcxx . . $ CppUtilities/Argument#::setSubArgumentscxx . . $ CppUtilities/Argument#setSubArguments(fd9df7cc6299ed0c).(const ArgumentInitializerListcxx . . $ CppUtilities/ArgumentInitializerList# &subArguments) |
| 618 | { |
| 619 | // remove this argument from the parents list of the previous secondary arguments |
| 620 | for (Argumentcxx . . $ CppUtilities/Argument# *const arg : m_subArgscxx . . $ CppUtilities/Argument#m_subArgs.) { |
| 621 | arg->m_parentscxx . . $ CppUtilities/Argument#m_parents..erasecxx . . $ std/vector#erase(cc2a997b00bceed8).(removecxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(459a7e7b9fbe7640).(arg->m_parentscxx . . $ CppUtilities/Argument#m_parents..begincxx . . $ std/vector#begin(55a6de06420d4903).(), arg->m_parentscxx . . $ CppUtilities/Argument#m_parents..endcxx . . $ std/vector#end(55a6de06420d4903).(), this), argcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(459a7e7b9fbe7640).->m_parentscxx . . $ CppUtilities/Argument#m_parents..endcxx . . $ std/vector#end(55a6de06420d4903).()); |
| 622 | } |
| 623 | // clear currently assigned args before adding new ones |
| 624 | m_subArgscxx . . $ CppUtilities/Argument#m_subArgs..clearcxx . . $ std/vector#clear(ced63f7c635d850d).(); |
| 625 | addSubArgumentscxx . . $ CppUtilities/Argument#addSubArguments(fd9df7cc6299ed0c).(subArguments); |
| 626 | } |
| 627 | |
| 628 | /*! |
| 629 | * \brief Sets the secondary arguments for this argument. |
| 630 | * |
| 631 | * The given arguments will be considered as secondary arguments of this argument by the argument parser. |
| 632 | * This means that the parser will complain if these arguments are given, but not this argument. |
| 633 | * If secondary arguments are labeled as mandatory their parent is also mandatory. |
| 634 | * |
| 635 | * The Argument does not take ownership. Do not destroy the given arguments as long as they are |
| 636 | * used as secondary arguments. |
| 637 | * |
| 638 | * \sa setSubArguments() |
| 639 | * \sa secondaryArguments() |
| 640 | * \sa addSecondaryArgument() |
| 641 | * \sa hasSubArguments() |
| 642 | */ |
| 643 | void Argumentcxx . . $ CppUtilities/Argument#::addSubArgumentscxx . . $ CppUtilities/Argument#addSubArguments(fd9df7cc6299ed0c).(const ArgumentInitializerListcxx . . $ CppUtilities/ArgumentInitializerList# &subArguments) |
| 644 | { |
| 645 | // append secondary arguments |
| 646 | const auto requiredCap = m_subArgscxx . . $ CppUtilities/Argument#m_subArgs..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() + subArguments.sizecxx . . $ std/initializer_list#size(c9b1e749b64d5edc).(); |
| 647 | if (requiredCap < m_subArgscxx . . $ CppUtilities/Argument#m_subArgs..capacitycxx . . $ std/vector#capacity(c9b1e749b64d5edc).()) { |
| 648 | m_subArgscxx . . $ CppUtilities/Argument#m_subArgs..reservecxx . . $ std/vector#reserve(2c44cd906ae4e829).(requiredCap); // does insert this for us? |
| 649 | } |
| 650 | m_subArgscxx . . $ CppUtilities/Argument#m_subArgs..insertcxx . . $ std/vector#insert(134ef7853f0b3ebe).(m_subArgscxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(459a7e7b9fbe7640)..endcxx . . $ std/vector#end(55a6de06420d4903).(), subArguments.begincxx . . $ std/initializer_list#begin(8e614c7de0b1573e).(), subArguments.endcxx . . $ std/initializer_list#end(8e614c7de0b1573e).()); |
| 651 | // add this argument to the parents list of the assigned secondary arguments and set the parser |
| 652 | for (Argumentcxx . . $ CppUtilities/Argument# *const arg : subArguments) { |
| 653 | if (findcxx . . $ std/find(a92da12e15934614).(arg->m_parentscxx . . $ CppUtilities/Argument#m_parents..cbegincxx . . $ std/vector#cbegin(d1e1699016b9d7e6).(), arg->m_parentscxx . . $ CppUtilities/Argument#m_parents..cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).(), this) ==cxx . . $ __gnu_cxx/`operator==`(30ee64f2df4eef8b). arg->m_parentscxx . . $ CppUtilities/Argument#m_parents..cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).()) { |
| 654 | arg->m_parentscxx . . $ CppUtilities/Argument#m_parents..push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(this); |
| 655 | } |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | /*! |
| 660 | * \brief Adds \a arg as a secondary argument for this argument. |
| 661 | * |
| 662 | * \sa secondaryArguments() |
| 663 | * \sa setSubArguments() |
| 664 | * \sa hasSubArguments() |
| 665 | */ |
| 666 | void Argumentcxx . . $ CppUtilities/Argument#::addSubArgumentcxx . . $ CppUtilities/Argument#addSubArgument(c2eefe819a479349).(Argumentcxx . . $ CppUtilities/Argument# *arg) |
| 667 | { |
| 668 | if (findcxx . . $ std/find(a92da12e15934614).(m_subArgscxx . . $ CppUtilities/Argument#m_subArgs..cbegincxx . . $ std/vector#cbegin(d1e1699016b9d7e6).(), m_subArgscxx . . $ CppUtilities/Argument#m_subArgs..cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).(), arg) !=cxx . . $ __gnu_cxx/`operator!=`(30ee64f2df4eef8b). m_subArgscxx . . $ CppUtilities/Argument#m_subArgs..cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).()) { |
| 669 | return; |
| 670 | } |
| 671 | m_subArgscxx . . $ CppUtilities/Argument#m_subArgs..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(arg); |
| 672 | if (findcxx . . $ std/find(a92da12e15934614).(arg->m_parentscxx . . $ CppUtilities/Argument#m_parents..cbegincxx . . $ std/vector#cbegin(d1e1699016b9d7e6).(), arg->m_parentscxx . . $ CppUtilities/Argument#m_parents..cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).(), this) ==cxx . . $ __gnu_cxx/`operator==`(30ee64f2df4eef8b). arg->m_parentscxx . . $ CppUtilities/Argument#m_parents..cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).()) { |
| 673 | arg->m_parentscxx . . $ CppUtilities/Argument#m_parents..push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(this); |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | /*! |
| 678 | * \brief Returns whether at least one parent argument is present. |
| 679 | * \remarks Returns always true for main arguments. |
| 680 | */ |
| 681 | bool Argumentcxx . . $ CppUtilities/Argument#::isParentPresentcxx . . $ CppUtilities/Argument#isParentPresent(50ce9a9e25b4a850).() const |
| 682 | { |
| 683 | if (isMainArgumentcxx . . $ CppUtilities/Argument#isMainArgument(50ce9a9e25b4a850).()) { |
| 684 | return true; |
| 685 | } |
| 686 | for (const Argumentcxx . . $ CppUtilities/Argument# *parent : m_parentscxx . . $ CppUtilities/Argument#m_parents.) { |
| 687 | if (parent->isPresentcxx . . $ CppUtilities/Argument#isPresent(50ce9a9e25b4a850).()) { |
| 688 | return true; |
| 689 | } |
| 690 | } |
| 691 | return false; |
| 692 | } |
| 693 | |
| 694 | /*! |
| 695 | * \brief Checks if this arguments conflicts with other arguments. |
| 696 | * |
| 697 | * If the argument is in conflict with an other argument this argument will be returned. |
| 698 | * Otherwise nullptr will be returned. |
| 699 | * |
| 700 | * \remarks Conflicts with main arguments aren't considered by this method! |
| 701 | */ |
| 702 | Argumentcxx . . $ CppUtilities/Argument# *Argumentcxx . . $ CppUtilities/Argument#::conflictsWithArgumentcxx . . $ CppUtilities/Argument#conflictsWithArgument(cb6a3fc127670316).() const |
| 703 | { |
| 704 | return isPresentcxx . . $ CppUtilities/Argument#isPresent(50ce9a9e25b4a850).() ? wouldConflictWithArgumentcxx . . $ CppUtilities/Argument#wouldConflictWithArgument(cb6a3fc127670316).() : nullptr; |
| 705 | } |
| 706 | |
| 707 | /*! |
| 708 | * \brief Checks if this argument would conflict with other arguments if it was present. |
| 709 | * |
| 710 | * If the argument is in conflict with an other argument this argument will be returned. |
| 711 | * Otherwise nullptr will be returned. |
| 712 | * |
| 713 | * \remarks Conflicts with main arguments aren't considered by this method! |
| 714 | */ |
| 715 | Argumentcxx . . $ CppUtilities/Argument# *Argumentcxx . . $ CppUtilities/Argument#::wouldConflictWithArgumentcxx . . $ CppUtilities/Argument#wouldConflictWithArgument(cb6a3fc127670316).() const |
| 716 | { |
| 717 | if (isCombinablecxx . . $ CppUtilities/Argument#isCombinable(50ce9a9e25b4a850).()) { |
| 718 | return nullptr; |
| 719 | } |
| 720 | for (Argumentcxx . . $ CppUtilities/Argument# *parent : m_parentscxx . . $ CppUtilities/Argument#m_parents.) { |
| 721 | for (Argumentcxx . . $ CppUtilities/Argument# *sibling : parent->subArgumentscxx . . $ CppUtilities/Argument#subArguments(1ef3bc1254d64c10).()) { |
| 722 | if (sibling != this && sibling->isPresentcxx . . $ CppUtilities/Argument#isPresent(50ce9a9e25b4a850).() && !sibling->isCombinablecxx . . $ CppUtilities/Argument#isCombinable(50ce9a9e25b4a850).()) { |
| 723 | return sibling; |
| 724 | } |
| 725 | } |
| 726 | } |
| 727 | return nullptr; |
| 728 | } |
| 729 | |
| 730 | /*! |
| 731 | * \brief Returns the first operation argument specified by the user or nullptr if no operation has been specified. |
| 732 | * \remarks Only direct sub arguments of this argument are considered. |
| 733 | */ |
| 734 | Argumentcxx . . $ CppUtilities/Argument# *Argumentcxx . . $ CppUtilities/Argument#::specifiedOperationcxx . . $ CppUtilities/Argument#specifiedOperation(cb6a3fc127670316).() const |
| 735 | { |
| 736 | for (Argumentcxx . . $ CppUtilities/Argument# *arg : m_subArgscxx . . $ CppUtilities/Argument#m_subArgs.) { |
| 737 | if (arg->denotesOperationcxx . . $ CppUtilities/Argument#denotesOperation(50ce9a9e25b4a850).() && arg->isPresentcxx . . $ CppUtilities/Argument#isPresent(50ce9a9e25b4a850).()) { |
| 738 | return arg; |
| 739 | } |
| 740 | } |
| 741 | return nullptr; |
| 742 | } |
| 743 | |
| 744 | /*! |
| 745 | * \brief Resets this argument and all sub arguments recursively. |
| 746 | * \sa Argument::reset() |
| 747 | */ |
| 748 | void Argumentcxx . . $ CppUtilities/Argument#::resetRecursivelycxx . . $ CppUtilities/Argument#resetRecursively(49f6e7a06ebc5aa8).() |
| 749 | { |
| 750 | for (Argumentcxx . . $ CppUtilities/Argument# *arg : m_subArgscxx . . $ CppUtilities/Argument#m_subArgs.) { |
| 751 | arg->resetRecursivelycxx . . $ CppUtilities/Argument#resetRecursively(49f6e7a06ebc5aa8).(); |
| 752 | } |
| 753 | resetcxx . . $ CppUtilities/Argument#reset(49f6e7a06ebc5aa8).(); |
| 754 | } |
| 755 | |
| 756 | /*! |
| 757 | * \class ArgumentParser |
| 758 | * \brief The ArgumentParser class provides a means for handling command line arguments. |
| 759 | * |
| 760 | * To setup the parser create instances of ApplicationUtilities::Argument to define a |
| 761 | * set of known arguments and assign these to the parser using setMainArguments(). |
| 762 | * |
| 763 | * To invoke parsing call parseArgs(). The parser will verify the previously |
| 764 | * assigned definitions (and might throw std::invalid_argument) and then parse the |
| 765 | * given command line arguments according the definitions (and might throw |
| 766 | * CppUtilities::Failure). |
| 767 | */ |
| 768 | |
| 769 | /*! |
| 770 | * \brief Constructs a new ArgumentParser. |
| 771 | */ |
| 772 | ArgumentParsercxx . . $ CppUtilities/ArgumentParser#::ArgumentParsercxx . . $ CppUtilities/ArgumentParser#ArgumentParser(49f6e7a06ebc5aa8).() |
| 773 | : m_actualArgccxx . . $ CppUtilities/ArgumentParser#m_actualArgc.(0) |
| 774 | , m_executablecxx . . $ CppUtilities/ArgumentParser#m_executable.(nullptr) |
| 775 | , m_unknownArgBehaviorcxx . . $ CppUtilities/ArgumentParser#m_unknownArgBehavior.(UnknownArgumentBehaviorcxx . . $ CppUtilities/UnknownArgumentBehavior#::Failcxx . . $ CppUtilities/UnknownArgumentBehavior#Fail.) |
| 776 | , m_defaultArgcxx . . $ CppUtilities/ArgumentParser#m_defaultArg.(nullptr) |
| 777 | , m_helpArgcxx . . $ CppUtilities/ArgumentParser#m_helpArg.(*this) |
| 778 | { |
| 779 | } |
| 780 | |
| 781 | /*! |
| 782 | * \brief Sets the main arguments for the parser. The parser will use these argument definitions |
| 783 | * to when parsing the command line arguments and when printing help information. |
| 784 | * \remarks |
| 785 | * - The parser does not take ownership. Do not destroy the arguments as long as they are used as |
| 786 | * main arguments. |
| 787 | * - Sets the first specified argument as default argument if none has been assigned yet and the |
| 788 | * first argument does not require any values or has no mandatory sub arguments. |
| 789 | */ |
| 790 | void ArgumentParsercxx . . $ CppUtilities/ArgumentParser#::setMainArgumentscxx . . $ CppUtilities/ArgumentParser#setMainArguments(fd9df7cc6299ed0c).(const ArgumentInitializerListcxx . . $ CppUtilities/ArgumentInitializerList# &mainArguments) |
| 791 | { |
| 792 | if (!mainArguments.sizecxx . . $ std/initializer_list#size(c9b1e749b64d5edc).()) { |
| 793 | m_mainArgscxx . . $ CppUtilities/ArgumentParser#m_mainArgs..clearcxx . . $ std/vector#clear(ced63f7c635d850d).(); |
| 794 | return; |
| 795 | } |
| 796 | for (Argumentcxx . . $ CppUtilities/Argument# *arg : mainArguments) { |
| 797 | arg->m_isMainArgcxx . . $ CppUtilities/Argument#m_isMainArg. = true; |
| 798 | } |
| 799 | m_mainArgscxx . . $ CppUtilities/ArgumentParser#m_mainArgs..assigncxx . . $ std/vector#assign(b6da5b9a9f304025).(mainArguments); |
| 800 | if (m_defaultArgcxx . . $ CppUtilities/ArgumentParser#m_defaultArg. || (*mainArguments.begincxx . . $ std/initializer_list#begin(8e614c7de0b1573e).())->requiredValueCountcxx . . $ CppUtilities/Argument#requiredValueCount(fe4d2d262d4164a8).()) { |
| 801 | return; |
| 802 | } |
| 803 | bool subArgsRequired = false; |
| 804 | for (const Argumentcxx . . $ CppUtilities/Argument# *subArg : (*mainArguments.begincxx . . $ std/initializer_list#begin(8e614c7de0b1573e).())->subArgumentscxx . . $ CppUtilities/Argument#subArguments(1ef3bc1254d64c10).()) { |
| 805 | if (subArg->isRequiredcxx . . $ CppUtilities/Argument#isRequired(50ce9a9e25b4a850).()) { |
| 806 | subArgsRequired = true; |
| 807 | break; |
| 808 | } |
| 809 | } |
| 810 | if (!subArgsRequired) { |
| 811 | m_defaultArgcxx . . $ CppUtilities/ArgumentParser#m_defaultArg. = *mainArguments.begincxx . . $ std/initializer_list#begin(8e614c7de0b1573e).(); |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | /*! |
| 816 | * \brief Adds the specified \a argument to the main argument. |
| 817 | * \remarks |
| 818 | * The parser does not take ownership. Do not destroy the argument as long as it is used as |
| 819 | * main argument. |
| 820 | */ |
| 821 | void ArgumentParsercxx . . $ CppUtilities/ArgumentParser#::addMainArgumentcxx . . $ CppUtilities/ArgumentParser#addMainArgument(c2eefe819a479349).(Argumentcxx . . $ CppUtilities/Argument# *argument) |
| 822 | { |
| 823 | argument->m_isMainArgcxx . . $ CppUtilities/Argument#m_isMainArg. = true; |
| 824 | m_mainArgscxx . . $ CppUtilities/ArgumentParser#m_mainArgs..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(argument); |
| 825 | } |
| 826 | |
| 827 | /*! |
| 828 | * \brief Prints help text for all assigned arguments. |
| 829 | */ |
| 830 | void ArgumentParsercxx . . $ CppUtilities/ArgumentParser#::printHelpcxx . . $ CppUtilities/ArgumentParser#printHelp(490063bd7e6d8d5d).(ostreamcxx . . $ std/ostream# &os) const |
| 831 | { |
| 832 | EscapeCodescxx . . $ CppUtilities/EscapeCodes/::setStylecxx . . $ CppUtilities/EscapeCodes/setStyle(347736b94b25c94c).(os, EscapeCodescxx . . $ CppUtilities/EscapeCodes/::TextAttributecxx . . $ CppUtilities/EscapeCodes/TextAttribute#::Boldcxx . . $ CppUtilities/EscapeCodes/TextAttribute#Bold.); |
| 833 | bool wroteLine = false; |
| 834 | if (applicationInfocxx . . $ CppUtilities/applicationInfo..namecxx . . $ CppUtilities/ApplicationInfo#name. && *applicationInfocxx . . $ CppUtilities/applicationInfo..namecxx . . $ CppUtilities/ApplicationInfo#name.) { |
| 835 | os <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). applicationInfocxx . . $ CppUtilities/applicationInfo..namecxx . . $ CppUtilities/ApplicationInfo#name.; |
| 836 | if (applicationInfocxx . . $ CppUtilities/applicationInfo..versioncxx . . $ CppUtilities/ApplicationInfo#version. && *applicationInfocxx . . $ CppUtilities/applicationInfo..versioncxx . . $ CppUtilities/ApplicationInfo#version.) { |
| 837 | os <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ',' <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' '; |
| 838 | } |
| 839 | wroteLine = true; |
| 840 | } |
| 841 | if (applicationInfocxx . . $ CppUtilities/applicationInfo..versioncxx . . $ CppUtilities/ApplicationInfo#version. && *applicationInfocxx . . $ CppUtilities/applicationInfo..versioncxx . . $ CppUtilities/ApplicationInfo#version.) { |
| 842 | os <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "version " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). applicationInfocxx . . $ CppUtilities/applicationInfo..versioncxx . . $ CppUtilities/ApplicationInfo#version.; |
| 843 | wroteLine = true; |
| 844 | } |
| 845 | if (wroteLine) { |
| 846 | os <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\n' <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\n'; |
| 847 | } |
| 848 | EscapeCodescxx . . $ CppUtilities/EscapeCodes/::setStylecxx . . $ CppUtilities/EscapeCodes/setStyle(347736b94b25c94c).(os); |
| 849 | |
| 850 | if (applicationInfocxx . . $ CppUtilities/applicationInfo..descriptioncxx . . $ CppUtilities/ApplicationInfo#description. && *applicationInfocxx . . $ CppUtilities/applicationInfo..descriptioncxx . . $ CppUtilities/ApplicationInfo#description.) { |
| 851 | os <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). applicationInfocxx . . $ CppUtilities/applicationInfo..descriptioncxx . . $ CppUtilities/ApplicationInfo#description.; |
| 852 | wroteLine = true; |
| 853 | } |
| 854 | if (wroteLine) { |
| 855 | os <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\n' <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\n'; |
| 856 | } |
| 857 | |
| 858 | if (!m_mainArgscxx . . $ CppUtilities/ArgumentParser#m_mainArgs..emptycxx . . $ std/vector#empty(3482b152b9333168).()) { |
| 859 | bool hasOperations = false, hasTopLevelOptions = false; |
| 860 | for (const Argumentcxx . . $ CppUtilities/Argument# *const arg : m_mainArgscxx . . $ CppUtilities/ArgumentParser#m_mainArgs.) { |
| 861 | if (arg->denotesOperationcxx . . $ CppUtilities/Argument#denotesOperation(50ce9a9e25b4a850).()) { |
| 862 | hasOperations = true; |
| 863 | } else if (strcmp(arg->namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).(), "help")) { |
| 864 | hasTopLevelOptions = true; |
| 865 | } |
| 866 | if (hasOperations && hasTopLevelOptions) { |
| 867 | break; |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | // check whether operations are available |
| 872 | if (hasOperations) { |
| 873 | // split top-level operations and other configurations |
| 874 | os <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Available operations:"; |
| 875 | for (const Argumentcxx . . $ CppUtilities/Argument# *const arg : m_mainArgscxx . . $ CppUtilities/ArgumentParser#m_mainArgs.) { |
| 876 | if (!arg->denotesOperationcxx . . $ CppUtilities/Argument#denotesOperation(50ce9a9e25b4a850).() || arg->isDeprecatedcxx . . $ CppUtilities/Argument#isDeprecated(50ce9a9e25b4a850).() || !strcmp(arg->namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).(), "help")) { |
| 877 | continue; |
| 878 | } |
| 879 | os <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\n'; |
| 880 | arg->printInfocxx . . $ CppUtilities/Argument#printInfo(26c0a26698046a31).(os); |
| 881 | } |
| 882 | if (hasTopLevelOptions) { |
| 883 | os <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\nAvailable top-level options:"; |
| 884 | for (const Argumentcxx . . $ CppUtilities/Argument# *const arg : m_mainArgscxx . . $ CppUtilities/ArgumentParser#m_mainArgs.) { |
| 885 | if (arg->denotesOperationcxx . . $ CppUtilities/Argument#denotesOperation(50ce9a9e25b4a850).() || arg->isDeprecatedcxx . . $ CppUtilities/Argument#isDeprecated(50ce9a9e25b4a850).() || !strcmp(arg->namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).(), "help")) { |
| 886 | continue; |
| 887 | } |
| 888 | os <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\n'; |
| 889 | arg->printInfocxx . . $ CppUtilities/Argument#printInfo(26c0a26698046a31).(os); |
| 890 | } |
| 891 | } |
| 892 | } else { |
| 893 | // just show all args if no operations are available |
| 894 | os <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Available arguments:"; |
| 895 | for (const Argumentcxx . . $ CppUtilities/Argument# *const arg : m_mainArgscxx . . $ CppUtilities/ArgumentParser#m_mainArgs.) { |
| 896 | if (arg->isDeprecatedcxx . . $ CppUtilities/Argument#isDeprecated(50ce9a9e25b4a850).() || !strcmp(arg->namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).(), "help")) { |
| 897 | continue; |
| 898 | } |
| 899 | os <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\n'; |
| 900 | arg->printInfocxx . . $ CppUtilities/Argument#printInfo(26c0a26698046a31).(os); |
| 901 | } |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | if (!applicationInfocxx . . $ CppUtilities/applicationInfo..dependencyVersionscxx . . $ CppUtilities/ApplicationInfo#dependencyVersions..emptycxx . . $ std/vector#empty(3482b152b9333168).()) { |
| 906 | os <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\n'; |
| 907 | auto i = applicationInfocxx . . $ CppUtilities/applicationInfo..dependencyVersionscxx . . $ CppUtilities/ApplicationInfo#dependencyVersions..begincxx . . $ std/vector#begin(55a6de06420d4903).(), end = applicationInfocxx . . $ CppUtilities/applicationInfo..dependencyVersionscxx . . $ CppUtilities/ApplicationInfo#dependencyVersions..endcxx . . $ std/vector#end(55a6de06420d4903).(); |
| 908 | os <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Linked against: " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).i; |
| 909 | for (++cxx . . $ __gnu_cxx/__normal_iterator#operator++(1613faa01bc3d014).i; i !=cxx . . $ __gnu_cxx/`operator!=`(30ee64f2df4eef8b). end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(1613faa01bc3d014).i) { |
| 910 | os <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ',' <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).i; |
| 911 | } |
| 912 | os <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\n'; |
| 913 | } |
| 914 | |
| 915 | if (applicationInfocxx . . $ CppUtilities/applicationInfo..urlcxx . . $ CppUtilities/ApplicationInfo#url. && *applicationInfocxx . . $ CppUtilities/applicationInfo..urlcxx . . $ CppUtilities/ApplicationInfo#url.) { |
| 916 | os <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\nProject website: " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). applicationInfocxx . . $ CppUtilities/applicationInfo..urlcxx . . $ CppUtilities/ApplicationInfo#url. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | /*! |
| 921 | * \brief Parses the specified command line arguments. |
| 922 | * |
| 923 | * The behavior is configurable by specifying the \a behavior argument. See ParseArgumentBehavior for |
| 924 | * the options. By default, all options are present. |
| 925 | * |
| 926 | * \remarks |
| 927 | * - The results are stored in the Argument instances assigned as main arguments and sub arguments. |
| 928 | * - This method will not return in the error case if the ParseArgumentBehavior::ExitOnFailure is present |
| 929 | * (default). |
| 930 | * - This method will not return in case shell completion is requested. This behavior can be altered |
| 931 | * by overriding the exit function via ArgumentParser::setExitFunction() which defaults to &std::exit. |
| 932 | * \throws Throws Failure if the specified arguments are invalid and the ParseArgumentBehavior::ExitOnFailure |
| 933 | * flag is *not* present. |
| 934 | * \sa readArgs() |
| 935 | */ |
| 936 | void ArgumentParsercxx . . $ CppUtilities/ArgumentParser#::parseArgscxx . . $ CppUtilities/ArgumentParser#parseArgs(539add8bb24c60d4).(int argc, const char *const *argv, ParseArgumentBehaviorcxx . . $ CppUtilities/ParseArgumentBehavior# behavior) |
| 937 | { |
| 938 | try { |
| 939 | readArgscxx . . $ CppUtilities/ArgumentParser#readArgs(5151383285df94d8).(argc, argv); |
| 940 | if (!argc) { |
| 941 | return; |
| 942 | } |
| 943 | if (behavior &cxx . . $ CppUtilities/`operator&`(f2029251cce91bbf). ParseArgumentBehaviorcxx . . $ CppUtilities/ParseArgumentBehavior#::CheckConstraintscxx . . $ CppUtilities/ParseArgumentBehavior#CheckConstraints.) { |
| 944 | checkConstraintscxx . . $ CppUtilities/ArgumentParser#checkConstraints(116237cab03ffd67).(m_mainArgscxx . . $ CppUtilities/ArgumentParser#m_mainArgs.); |
| 945 | } |
| 946 | if (behavior &cxx . . $ CppUtilities/`operator&`(f2029251cce91bbf). ParseArgumentBehaviorcxx . . $ CppUtilities/ParseArgumentBehavior#::InvokeCallbackscxx . . $ CppUtilities/ParseArgumentBehavior#InvokeCallbacks.) { |
| 947 | invokeCallbackscxx . . $ CppUtilities/ArgumentParser#invokeCallbacks(116237cab03ffd67).(m_mainArgscxx . . $ CppUtilities/ArgumentParser#m_mainArgs.); |
| 948 | } |
| 949 | } catch (const ParseErrorcxx . . $ CppUtilities/ParseError# &failure) { |
| 950 | if (behavior &cxx . . $ CppUtilities/`operator&`(f2029251cce91bbf). ParseArgumentBehaviorcxx . . $ CppUtilities/ParseArgumentBehavior#::ExitOnFailurecxx . . $ CppUtilities/ParseArgumentBehavior#ExitOnFailure.) { |
| 951 | CMD_UTILS_START_CONSOLEcxx . . $ `application/commandlineutils.h:35:9`!; |
| 952 | cerrcxx . . $ std/cerr. <<cxx . . $ CppUtilities/`operator<<`(3b9e0a4d94d289c5). failure; |
| 953 | invokeExitcxx . . $ CppUtilities/ArgumentParser#invokeExit(d4f767463ce0a6b3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 954 | } |
| 955 | throw; |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | /*! |
| 960 | * \brief Parses the specified command line arguments. |
| 961 | * \remarks |
| 962 | * - The results are stored in the Argument instances assigned as main arguments and sub arguments. |
| 963 | * - In contrast to parseArgs() this method does not check whether constraints are violated and it |
| 964 | * does not call any callbacks. |
| 965 | * - This method will not return in case shell completion is requested. This behavior can be altered |
| 966 | * by overriding the exit function via ArgumentParser::setExitFunction() which defaults to &std::exit. |
| 967 | * \throws Throws Failure if the specified arguments are invalid. |
| 968 | * \sa parseArgs() |
| 969 | * \deprecated In next major release, this method will be private. parseArgs() can serve the same |
| 970 | * purpose then. |
| 971 | */ |
| 972 | void ArgumentParsercxx . . $ CppUtilities/ArgumentParser#::readArgscxx . . $ CppUtilities/ArgumentParser#readArgs(5151383285df94d8).(int argc, const char *const *argv) |
| 973 | { |
| 974 | CPP_UTILITIES_IF_DEBUG_BUILDcxx . . $ `application/global.h:118:9`!(verifyArgs(m_mainArgs);) |
| 975 | m_actualArgccxx . . $ CppUtilities/ArgumentParser#m_actualArgc. = 0; |
| 976 | |
| 977 | // the first argument is the executable name |
| 978 | if (!argc) { |
| 979 | m_executablecxx . . $ CppUtilities/ArgumentParser#m_executable. = nullptr; |
| 980 | return; |
| 981 | } |
| 982 | m_executablecxx . . $ CppUtilities/ArgumentParser#m_executable. = *argv; |
| 983 | |
| 984 | // check for further arguments |
| 985 | if (!--argc) { |
| 986 | // no arguments specified -> flag default argument as present if one is assigned |
| 987 | assumeDefaultArgumentcxx . . $ CppUtilities/ArgumentParser#assumeDefaultArgument(49f6e7a06ebc5aa8).(); |
| 988 | return; |
| 989 | } |
| 990 | |
| 991 | // check for completion mode: if first arg (after executable name) is "--bash-completion-for", bash completion for the following arguments is requested |
| 992 | const bool completionMode = !strcmp(*++argv, "--bash-completion-for"); |
| 993 | |
| 994 | // determine the index of the current word for completion and the number of arguments to be passed to ArgumentReader |
| 995 | unsigned int currentWordIndex = 0, argcForReader; |
| 996 | if (completionMode) { |
| 997 | // the first argument after "--bash-completion-for" is the index of the current word |
| 998 | try { |
| 999 | currentWordIndex = (--argc ? stringToNumbercxx . . $ CppUtilities/stringToNumber(478c46a825b2cbff).<unsigned int, stringcxx . . $ std/string#>(*cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).(++argv)) : 0); |
| 1000 | if (argc) { |
| 1001 | ++argv; |
| 1002 | --argc; |
| 1003 | } |
| 1004 | } catch (const ConversionExceptioncxx . . $ CppUtilities/ConversionException# &) { |
| 1005 | currentWordIndex = static_cast<unsigned int>(argc - 1); |
| 1006 | } |
| 1007 | argcForReader = mincxx . . $ std/min(2a338fce5842aa6a).(static_cast<unsigned int>(argc), currentWordIndex + 1); |
| 1008 | } else { |
| 1009 | argcForReader = static_cast<unsigned int>(argc); |
| 1010 | } |
| 1011 | |
| 1012 | // read specified arguments |
| 1013 | ArgumentReadercxx . . $ CppUtilities/ArgumentReader# readercxx . . $ CppUtilities/ArgumentReader#ArgumentReader(5d9014cd7706224b).(*this, argv, argv + argcForReader, completionMode); |
| 1014 | const bool allArgsProcessed(reader.readcxx . . $ CppUtilities/ArgumentReader#read(c9857a73d68e59ba).()); |
| 1015 | m_noColorArgcxx . . $ CppUtilities/ArgumentParser#m_noColorArg..applycxx . . $ CppUtilities/NoColorArgument#apply(83f5f38750778ac8).(); |
| 1016 | |
| 1017 | // fail when not all arguments could be processed, except when in completion mode |
| 1018 | if (!completionMode && !allArgsProcessed) { |
| 1019 | const auto suggestions(findSuggestionscxx . . $ CppUtilities/ArgumentParser#findSuggestions(6a143a656ff85f6c).(argc, argv, static_cast<unsigned int>(argc - 1), reader)); |
| 1020 | throw ParseErrorcxx . . $ CppUtilities/ParseError#(argsToStringcxx . . $ CppUtilities/argsToString(2bd17df601864384).("The specified argument \"", *reader.argvcxx . . $ CppUtilities/ArgumentReader#argv., "\" is unknown.", suggestions)); |
| 1021 | } |
| 1022 | |
| 1023 | // print Bash completion and prevent the application to continue with the regular execution |
| 1024 | if (completionMode) { |
| 1025 | printBashCompletioncxx . . $ CppUtilities/ArgumentParser#printBashCompletion(34b204d995c4289d).(argc, argv, currentWordIndex, reader); |
| 1026 | invokeExitcxx . . $ CppUtilities/ArgumentParser#invokeExit(d4f767463ce0a6b3).(EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`!); |
| 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | /*! |
| 1031 | * \brief Resets all Argument instances assigned as mainArguments() and sub arguments. |
| 1032 | * \sa Argument::reset() |
| 1033 | */ |
| 1034 | void ArgumentParsercxx . . $ CppUtilities/ArgumentParser#::resetArgscxx . . $ CppUtilities/ArgumentParser#resetArgs(49f6e7a06ebc5aa8).() |
| 1035 | { |
| 1036 | for (Argumentcxx . . $ CppUtilities/Argument# *arg : m_mainArgscxx . . $ CppUtilities/ArgumentParser#m_mainArgs.) { |
| 1037 | arg->resetRecursivelycxx . . $ CppUtilities/Argument#resetRecursively(49f6e7a06ebc5aa8).(); |
| 1038 | } |
| 1039 | m_actualArgccxx . . $ CppUtilities/ArgumentParser#m_actualArgc. = 0; |
| 1040 | } |
| 1041 | |
| 1042 | /*! |
| 1043 | * \brief Assumes the default argument is present (if not already present). |
| 1044 | * \remarks |
| 1045 | * - Adds an occurrence to the default argument so this argument is assumed to be present (even though |
| 1046 | * it is not actually present). |
| 1047 | * - This function is automatically called if there are no arguments present at all. |
| 1048 | * - This function may be called manually if no actually relevant arguments are present, e.g. if only |
| 1049 | * global flags are present but no main operation argument. Note that for this concrete example there |
| 1050 | * is also ensureDefaultOperation() (which will call assumeDefaultArgument() internally). |
| 1051 | */ |
| 1052 | void ArgumentParsercxx . . $ CppUtilities/ArgumentParser#::assumeDefaultArgumentcxx . . $ CppUtilities/ArgumentParser#assumeDefaultArgument(49f6e7a06ebc5aa8).() |
| 1053 | { |
| 1054 | if (m_defaultArgcxx . . $ CppUtilities/ArgumentParser#m_defaultArg. && m_defaultArgcxx . . $ CppUtilities/ArgumentParser#m_defaultArg.->m_occurrencescxx . . $ CppUtilities/Argument#m_occurrences..emptycxx . . $ std/vector#empty(3482b152b9333168).()) { |
| 1055 | m_defaultArgcxx . . $ CppUtilities/ArgumentParser#m_defaultArg.->m_occurrencescxx . . $ CppUtilities/Argument#m_occurrences..emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(0); |
| 1056 | } |
| 1057 | } |
| 1058 | |
| 1059 | /*! |
| 1060 | * \brief Ensures a main operation argument is present. |
| 1061 | * \remarks |
| 1062 | * - Assumes the default argument is present if no other main operation argument or the help argument |
| 1063 | * is present. |
| 1064 | * - Requires the default argument to be an operation argument. |
| 1065 | */ |
| 1066 | void ArgumentParsercxx . . $ CppUtilities/ArgumentParser#::ensureDefaultOperationcxx . . $ CppUtilities/ArgumentParser#ensureDefaultOperation(49f6e7a06ebc5aa8).() |
| 1067 | { |
| 1068 | if (!m_defaultArgcxx . . $ CppUtilities/ArgumentParser#m_defaultArg. || m_defaultArgcxx . . $ CppUtilities/ArgumentParser#m_defaultArg.->isPresentcxx . . $ CppUtilities/Argument#isPresent(50ce9a9e25b4a850).() || !m_defaultArgcxx . . $ CppUtilities/ArgumentParser#m_defaultArg.->denotesOperationcxx . . $ CppUtilities/Argument#denotesOperation(50ce9a9e25b4a850).()) { |
| 1069 | return; |
| 1070 | } |
| 1071 | for (auto *const arg : m_mainArgscxx . . $ CppUtilities/ArgumentParser#m_mainArgs.) { |
| 1072 | if (arg->isPresentcxx . . $ CppUtilities/Argument#isPresent(50ce9a9e25b4a850).() && (arg->denotesOperationcxx . . $ CppUtilities/Argument#denotesOperation(50ce9a9e25b4a850).() || arg == &m_helpArgcxx . . $ CppUtilities/ArgumentParser#m_helpArg.)) { |
| 1073 | return; |
| 1074 | } |
| 1075 | } |
| 1076 | assumeDefaultArgumentcxx . . $ CppUtilities/ArgumentParser#assumeDefaultArgument(49f6e7a06ebc5aa8).(); |
| 1077 | } |
| 1078 | |
| 1079 | /*! |
| 1080 | * \brief Returns the first operation argument specified by the user or nullptr if no operation has been specified. |
| 1081 | * \remarks Only main arguments are considered. See Argument::specifiedOperation() to check sub arguments of a specific |
| 1082 | * argument. |
| 1083 | */ |
| 1084 | Argumentcxx . . $ CppUtilities/Argument# *ArgumentParsercxx . . $ CppUtilities/ArgumentParser#::specifiedOperationcxx . . $ CppUtilities/ArgumentParser#specifiedOperation(cb6a3fc127670316).() const |
| 1085 | { |
| 1086 | for (Argumentcxx . . $ CppUtilities/Argument# *arg : m_mainArgscxx . . $ CppUtilities/ArgumentParser#m_mainArgs.) { |
| 1087 | if (arg->denotesOperationcxx . . $ CppUtilities/Argument#denotesOperation(50ce9a9e25b4a850).() && arg->isPresentcxx . . $ CppUtilities/Argument#isPresent(50ce9a9e25b4a850).()) { |
| 1088 | return arg; |
| 1089 | } |
| 1090 | } |
| 1091 | return nullptr; |
| 1092 | } |
| 1093 | |
| 1094 | /*! |
| 1095 | * \brief Checks whether at least one uncombinable main argument is present. |
| 1096 | */ |
| 1097 | bool ArgumentParsercxx . . $ CppUtilities/ArgumentParser#::isUncombinableMainArgPresentcxx . . $ CppUtilities/ArgumentParser#isUncombinableMainArgPresent(50ce9a9e25b4a850).() const |
| 1098 | { |
| 1099 | for (const Argumentcxx . . $ CppUtilities/Argument# *arg : m_mainArgscxx . . $ CppUtilities/ArgumentParser#m_mainArgs.) { |
| 1100 | if (!arg->isCombinablecxx . . $ CppUtilities/Argument#isCombinable(50ce9a9e25b4a850).() && arg->isPresentcxx . . $ CppUtilities/Argument#isPresent(50ce9a9e25b4a850).()) { |
| 1101 | return true; |
| 1102 | } |
| 1103 | } |
| 1104 | return false; |
| 1105 | } |
| 1106 | |
| 1107 | #ifdef CPP_UTILITIES_DEBUG_BUILD |
| 1108 | /*! |
| 1109 | * \brief Verifies the specified \a argument definitions. |
| 1110 | * |
| 1111 | * Asserts that |
| 1112 | * - The same argument has not been added twice to the same parent. |
| 1113 | * - Only one argument within a parent is default or implicit. |
| 1114 | * - Only main arguments denote operations. |
| 1115 | * - Argument abbreviations are unique within the same level. |
| 1116 | * - Argument names are unique within within the same level. |
| 1117 | * |
| 1118 | * \remarks |
| 1119 | * - Verifies the sub arguments, too. |
| 1120 | * - For debugging purposes only; hence only used in debug builds. |
| 1121 | */ |
| 1122 | void ArgumentParser::verifyArgs(const ArgumentVector &args) |
| 1123 | { |
| 1124 | vector<const Argument *> verifiedArgs; |
| 1125 | verifiedArgs.reserve(args.size()); |
| 1126 | vector<char> abbreviations; |
| 1127 | abbreviations.reserve(abbreviations.size() + args.size()); |
| 1128 | vector<const char *> names; |
| 1129 | names.reserve(names.size() + args.size()); |
| 1130 | bool hasImplicit = false; |
| 1131 | for (const Argument *arg : args) { |
| 1132 | assert(find(verifiedArgs.cbegin(), verifiedArgs.cend(), arg) == verifiedArgs.cend()); |
| 1133 | verifiedArgs.push_back(arg); |
| 1134 | assert(!arg->isImplicit() || !hasImplicit); |
| 1135 | hasImplicit |= arg->isImplicit(); |
| 1136 | assert(!arg->abbreviation() || find(abbreviations.cbegin(), abbreviations.cend(), arg->abbreviation()) == abbreviations.cend()); |
| 1137 | abbreviations.push_back(arg->abbreviation()); |
| 1138 | assert(!arg->name() || find_if(names.cbegin(), names.cend(), [arg](const char *name) { return !strcmp(arg->name(), name); }) == names.cend()); |
| 1139 | assert(arg->requiredValueCount() == 0 || arg->subArguments().size() == 0 || (arg->flags() & Argument::Flags::Greedy)); |
| 1140 | names.emplace_back(arg->name()); |
| 1141 | } |
| 1142 | for (const Argument *arg : args) { |
| 1143 | verifyArgs(arg->subArguments()); |
| 1144 | } |
| 1145 | } |
| 1146 | #endif |
| 1147 | |
| 1148 | /*! |
| 1149 | * \brief Returns whether \a arg1 should be listed before \a arg2 when |
| 1150 | * printing completion. |
| 1151 | * |
| 1152 | * Arguments are sorted by name (ascending order). However, all arguments |
| 1153 | * denoting an operation are listed before all other arguments. |
| 1154 | */ |
| 1155 | bool compareArgscxx . . $ CppUtilities/compareArgs(2a2599e577fc7676).(const Argumentcxx . . $ CppUtilities/Argument# *arg1, const Argumentcxx . . $ CppUtilities/Argument# *arg2) |
| 1156 | { |
| 1157 | if (arg1->denotesOperationcxx . . $ CppUtilities/Argument#denotesOperation(50ce9a9e25b4a850).() && !arg2->denotesOperationcxx . . $ CppUtilities/Argument#denotesOperation(50ce9a9e25b4a850).()) { |
| 1158 | return true; |
| 1159 | } else if (!arg1->denotesOperationcxx . . $ CppUtilities/Argument#denotesOperation(50ce9a9e25b4a850).() && arg2->denotesOperationcxx . . $ CppUtilities/Argument#denotesOperation(50ce9a9e25b4a850).()) { |
| 1160 | return false; |
| 1161 | } else { |
| 1162 | return strcmp(arg1->namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).(), arg2->namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).()) < 0; |
| 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | /*! |
| 1167 | * \brief Inserts the specified \a siblings in the \a target list. |
| 1168 | * \remarks Only inserts siblings which could still occur at least once more. |
| 1169 | */ |
| 1170 | void insertSiblingscxx . . $ CppUtilities/insertSiblings(361ce6137eba976d).(const ArgumentVectorcxx . . $ CppUtilities/ArgumentVector# &siblings, listcxx . . $ std/__cxx11/list#<const Argumentcxx . . $ CppUtilities/Argument# *> &target) |
| 1171 | { |
| 1172 | bool onlyCombinable = false; |
| 1173 | for (const Argumentcxx . . $ CppUtilities/Argument# *sibling : siblings) { |
| 1174 | if (sibling->isPresentcxx . . $ CppUtilities/Argument#isPresent(50ce9a9e25b4a850).() && !sibling->isCombinablecxx . . $ CppUtilities/Argument#isCombinable(50ce9a9e25b4a850).()) { |
| 1175 | onlyCombinable = true; |
| 1176 | break; |
| 1177 | } |
| 1178 | } |
| 1179 | for (const Argumentcxx . . $ CppUtilities/Argument# *sibling : siblings) { |
| 1180 | if ((!onlyCombinable || sibling->isCombinablecxx . . $ CppUtilities/Argument#isCombinable(50ce9a9e25b4a850).()) && sibling->occurrencescxx . . $ CppUtilities/Argument#occurrences(fe4d2d262d4164a8).() < sibling->maxOccurrencescxx . . $ CppUtilities/Argument#maxOccurrences(fe4d2d262d4164a8).()) { |
| 1181 | target.push_backcxx . . $ std/__cxx11/list#push_back(77d9f17553126ecb).(sibling); |
| 1182 | } |
| 1183 | } |
| 1184 | } |
| 1185 | |
| 1186 | /*! |
| 1187 | * \brief Determines arguments relevant for Bash completion or suggestions in case of typo. |
| 1188 | */ |
| 1189 | ArgumentCompletionInfocxx . . $ CppUtilities/ArgumentCompletionInfo# ArgumentParsercxx . . $ CppUtilities/ArgumentParser#::determineCompletionInfocxx . . $ CppUtilities/ArgumentParser#determineCompletionInfo(a82f731a26a5c72e).( |
| 1190 | int argc, const char *const *argv, unsigned int currentWordIndex, const ArgumentReadercxx . . $ CppUtilities/ArgumentReader# &reader) const |
| 1191 | { |
| 1192 | ArgumentCompletionInfocxx . . $ CppUtilities/ArgumentCompletionInfo# completioncxx . . $ CppUtilities/ArgumentCompletionInfo#ArgumentCompletionInfo(a92acb73639bd8f5).(reader); |
| 1193 | |
| 1194 | // determine last detected arg |
| 1195 | if (completion.lastDetectedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArg.) { |
| 1196 | completion.lastDetectedArgIndexcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArgIndex. = static_cast<size_t>(reader.lastArgDenotationcxx . . $ CppUtilities/ArgumentReader#lastArgDenotation. - argv); |
| 1197 | completion.lastDetectedArgPathcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArgPath. =cxx . . $ std/vector#`operator=`(e6b68e61becad66f). completion.lastDetectedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArg.->pathcxx . . $ CppUtilities/Argument#path(b87142e1c5eb1796).(completion.lastDetectedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArg.->occurrencescxx . . $ CppUtilities/Argument#occurrences(fe4d2d262d4164a8).() - 1); |
| 1198 | } |
| 1199 | |
| 1200 | // determine last arg, omitting trailing empty args |
| 1201 | if (argc) { |
| 1202 | completion.lastSpecifiedArgIndexcxx . . $ CppUtilities/ArgumentCompletionInfo#lastSpecifiedArgIndex. = static_cast<unsigned int>(argc) - 1; |
| 1203 | completion.lastSpecifiedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastSpecifiedArg. = argv + completion.lastSpecifiedArgIndexcxx . . $ CppUtilities/ArgumentCompletionInfo#lastSpecifiedArgIndex.; |
| 1204 | for (; completion.lastSpecifiedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastSpecifiedArg. >= argv && **completion.lastSpecifiedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastSpecifiedArg. == '\0'; |
| 1205 | --completion.lastSpecifiedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastSpecifiedArg., --completion.lastSpecifiedArgIndexcxx . . $ CppUtilities/ArgumentCompletionInfo#lastSpecifiedArgIndex.) |
| 1206 | ; |
| 1207 | } |
| 1208 | |
| 1209 | // just return main arguments if no args detected |
| 1210 | if (!completion.lastDetectedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArg. || !completion.lastDetectedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArg.->isPresentcxx . . $ CppUtilities/Argument#isPresent(50ce9a9e25b4a850).()) { |
| 1211 | completion.nextArgumentOrValuecxx . . $ CppUtilities/ArgumentCompletionInfo#nextArgumentOrValue. = true; |
| 1212 | insertSiblingscxx . . $ CppUtilities/insertSiblings(361ce6137eba976d).(m_mainArgscxx . . $ CppUtilities/ArgumentParser#m_mainArgs., completion.relevantArgscxx . . $ CppUtilities/ArgumentCompletionInfo#relevantArgs.); |
| 1213 | completion.relevantArgscxx . . $ CppUtilities/ArgumentCompletionInfo#relevantArgs..sortcxx . . $ std/__cxx11/list#sort(b07662a27bd562f9).(compareArgscxx . . $ CppUtilities/compareArgs(2a2599e577fc7676).); |
| 1214 | return completion; |
| 1215 | } |
| 1216 | |
| 1217 | completion.nextArgumentOrValuecxx . . $ CppUtilities/ArgumentCompletionInfo#nextArgumentOrValue. = currentWordIndex > completion.lastDetectedArgIndexcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArgIndex.; |
| 1218 | if (!completion.nextArgumentOrValuecxx . . $ CppUtilities/ArgumentCompletionInfo#nextArgumentOrValue.) { |
| 1219 | // since the argument could be detected (hopefully unambiguously?) just return it for "final completion" |
| 1220 | completion.relevantArgscxx . . $ CppUtilities/ArgumentCompletionInfo#relevantArgs..push_backcxx . . $ std/__cxx11/list#push_back(77d9f17553126ecb).(completion.lastDetectedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArg.); |
| 1221 | completion.relevantArgscxx . . $ CppUtilities/ArgumentCompletionInfo#relevantArgs..sortcxx . . $ std/__cxx11/list#sort(b07662a27bd562f9).(compareArgscxx . . $ CppUtilities/compareArgs(2a2599e577fc7676).); |
| 1222 | return completion; |
| 1223 | } |
| 1224 | |
| 1225 | // define function to add parameter values of argument as possible completions |
| 1226 | const auto addValueCompletionsForArg = [&completion](const Argumentcxx . . $ CppUtilities/Argument# *arg) { |
| 1227 | if (arg->valueCompletionBehaviourcxx . . $ CppUtilities/Argument#valueCompletionBehaviour(e66dc16b08d52b98).() &cxx . . $ CppUtilities/`operator&`(83f89e59cac566d1). ValueCompletionBehaviorcxx . . $ CppUtilities/ValueCompletionBehavior#::PreDefinedValuescxx . . $ CppUtilities/ValueCompletionBehavior#PreDefinedValues.) { |
| 1228 | completion.relevantPreDefinedValuescxx . . $ CppUtilities/ArgumentCompletionInfo#relevantPreDefinedValues..push_backcxx . . $ std/__cxx11/list#push_back(77d9f17553126ecb).(arg); |
| 1229 | } |
| 1230 | if (!(arg->valueCompletionBehaviourcxx . . $ CppUtilities/Argument#valueCompletionBehaviour(e66dc16b08d52b98).() &cxx . . $ CppUtilities/`operator&`(83f89e59cac566d1). ValueCompletionBehaviorcxx . . $ CppUtilities/ValueCompletionBehavior#::FileSystemIfNoPreDefinedValuescxx . . $ CppUtilities/ValueCompletionBehavior#FileSystemIfNoPreDefinedValues.) || !arg->preDefinedCompletionValuescxx . . $ CppUtilities/Argument#preDefinedCompletionValues(a9f41ea0e82d88cf).()) { |
| 1231 | completion.completeFilescxx . . $ CppUtilities/ArgumentCompletionInfo#completeFiles. = completion.completeFilescxx . . $ CppUtilities/ArgumentCompletionInfo#completeFiles. || arg->valueCompletionBehaviourcxx . . $ CppUtilities/Argument#valueCompletionBehaviour(e66dc16b08d52b98).() &cxx . . $ CppUtilities/`operator&`(83f89e59cac566d1). ValueCompletionBehaviorcxx . . $ CppUtilities/ValueCompletionBehavior#::Filescxx . . $ CppUtilities/ValueCompletionBehavior#Files.; |
| 1232 | completion.completeDirscxx . . $ CppUtilities/ArgumentCompletionInfo#completeDirs. = completion.completeDirscxx . . $ CppUtilities/ArgumentCompletionInfo#completeDirs. || arg->valueCompletionBehaviourcxx . . $ CppUtilities/Argument#valueCompletionBehaviour(e66dc16b08d52b98).() &cxx . . $ CppUtilities/`operator&`(83f89e59cac566d1). ValueCompletionBehaviorcxx . . $ CppUtilities/ValueCompletionBehavior#::Directoriescxx . . $ CppUtilities/ValueCompletionBehavior#Directories.; |
| 1233 | } |
| 1234 | }; |
| 1235 | |
| 1236 | // detect number of specified values |
| 1237 | auto currentValueCount = completion.lastDetectedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArg.->valuescxx . . $ CppUtilities/Argument#values(f310c0743d72f851).(completion.lastDetectedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArg.->occurrencescxx . . $ CppUtilities/Argument#occurrences(fe4d2d262d4164a8).() - 1).sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); |
| 1238 | // ignore values which are specified after the current word |
| 1239 | if (currentValueCount) { |
| 1240 | const auto currentWordIndexRelativeToLastDetectedArg = currentWordIndex - completion.lastDetectedArgIndexcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArgIndex.; |
| 1241 | if (currentValueCount > currentWordIndexRelativeToLastDetectedArg) { |
| 1242 | currentValueCount -= currentWordIndexRelativeToLastDetectedArg; |
| 1243 | } else { |
| 1244 | currentValueCount = 0; |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | // add value completions for implicit child if there are no value specified and there are no values required by the |
| 1249 | // last detected argument itself |
| 1250 | if (!currentValueCount && !completion.lastDetectedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArg.->requiredValueCountcxx . . $ CppUtilities/Argument#requiredValueCount(fe4d2d262d4164a8).()) { |
| 1251 | for (const Argumentcxx . . $ CppUtilities/Argument# *child : completion.lastDetectedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArg.->subArgumentscxx . . $ CppUtilities/Argument#subArguments(1ef3bc1254d64c10).()) { |
| 1252 | if (child->isImplicitcxx . . $ CppUtilities/Argument#isImplicit(50ce9a9e25b4a850).() && child->requiredValueCountcxx . . $ CppUtilities/Argument#requiredValueCount(fe4d2d262d4164a8).()) { |
| 1253 | addValueCompletionsForArg(cxx . . $ CppUtilities/ArgumentParser#determineCompletionInfo(a82f731a26a5c72e).$anonymous_type_0#`operator()`(7b6562d90823ae15).child); |
| 1254 | break; |
| 1255 | } |
| 1256 | } |
| 1257 | } |
| 1258 | |
| 1259 | // add value completions for last argument if there are further values required |
| 1260 | if (completion.lastDetectedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArg.->requiredValueCountcxx . . $ CppUtilities/Argument#requiredValueCount(fe4d2d262d4164a8).() == Argumentcxx . . $ CppUtilities/Argument#::varValueCountcxx . . $ CppUtilities/Argument#varValueCount. |
| 1261 | || (currentValueCount < completion.lastDetectedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArg.->requiredValueCountcxx . . $ CppUtilities/Argument#requiredValueCount(fe4d2d262d4164a8).())) { |
| 1262 | addValueCompletionsForArg(cxx . . $ CppUtilities/ArgumentParser#determineCompletionInfo(a82f731a26a5c72e).$anonymous_type_0#`operator()`(7b6562d90823ae15).completion.lastDetectedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArg.); |
| 1263 | } |
| 1264 | |
| 1265 | if (completion.lastDetectedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArg.->requiredValueCountcxx . . $ CppUtilities/Argument#requiredValueCount(fe4d2d262d4164a8).() == Argumentcxx . . $ CppUtilities/Argument#::varValueCountcxx . . $ CppUtilities/Argument#varValueCount. |
| 1266 | || completion.lastDetectedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArg.->valuescxx . . $ CppUtilities/Argument#values(f310c0743d72f851).(completion.lastDetectedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArg.->occurrencescxx . . $ CppUtilities/Argument#occurrences(fe4d2d262d4164a8).() - 1).sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() |
| 1267 | >= completion.lastDetectedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArg.->requiredValueCountcxx . . $ CppUtilities/Argument#requiredValueCount(fe4d2d262d4164a8).()) { |
| 1268 | // sub arguments of the last arg are possible completions |
| 1269 | for (const Argumentcxx . . $ CppUtilities/Argument# *subArg : completion.lastDetectedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArg.->subArgumentscxx . . $ CppUtilities/Argument#subArguments(1ef3bc1254d64c10).()) { |
| 1270 | if (subArg->occurrencescxx . . $ CppUtilities/Argument#occurrences(fe4d2d262d4164a8).() < subArg->maxOccurrencescxx . . $ CppUtilities/Argument#maxOccurrences(fe4d2d262d4164a8).()) { |
| 1271 | completion.relevantArgscxx . . $ CppUtilities/ArgumentCompletionInfo#relevantArgs..push_backcxx . . $ std/__cxx11/list#push_back(77d9f17553126ecb).(subArg); |
| 1272 | } |
| 1273 | } |
| 1274 | |
| 1275 | // siblings of parents are possible completions as well |
| 1276 | for (auto parentArgument = completion.lastDetectedArgPathcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArgPath..crbegincxx . . $ std/vector#crbegin(7ffd9c4e53ea04dd).(), end = completion.lastDetectedArgPathcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArgPath..crendcxx . . $ std/vector#crend(7ffd9c4e53ea04dd).();; ++cxx . . $ std/reverse_iterator#operator++(b4fad7494eaaab68).parentArgument) { |
| 1277 | insertSiblingscxx . . $ CppUtilities/insertSiblings(361ce6137eba976d).(parentArgument !=cxx . . $ std/`operator!=`(c2ad8cf295ccec45). end ? (*cxx . . $ std/reverse_iterator#`operator*`(c076846f881f3e7e).parentArgument)->subArgumentscxx . . $ CppUtilities/Argument#subArguments(1ef3bc1254d64c10).() : m_mainArgscxx . . $ CppUtilities/ArgumentParser#m_mainArgs., completion.relevantArgscxx . . $ CppUtilities/ArgumentCompletionInfo#relevantArgs.); |
| 1278 | if (parentArgument ==cxx . . $ std/`operator==`(c2ad8cf295ccec45). end) { |
| 1279 | break; |
| 1280 | } |
| 1281 | } |
| 1282 | } |
| 1283 | |
| 1284 | return completion; |
| 1285 | } |
| 1286 | |
| 1287 | /*! |
| 1288 | * \brief Returns the suggestion string printed in error case due to unknown arguments. |
| 1289 | */ |
| 1290 | stringcxx . . $ std/string# ArgumentParsercxx . . $ CppUtilities/ArgumentParser#::findSuggestionscxx . . $ CppUtilities/ArgumentParser#findSuggestions(6a143a656ff85f6c).(int argc, const char *const *argv, unsigned int cursorPos, const ArgumentReadercxx . . $ CppUtilities/ArgumentReader# &reader) const |
| 1291 | { |
| 1292 | // determine completion info |
| 1293 | const auto completionInfo(determineCompletionInfocxx . . $ CppUtilities/ArgumentParser#determineCompletionInfo(a82f731a26a5c72e).(argc, argv, cursorPos, reader)); |
| 1294 | |
| 1295 | // determine the unknown/misspelled argument |
| 1296 | const auto *unknownArg(*reader.argvcxx . . $ CppUtilities/ArgumentReader#argv.); |
| 1297 | auto unknownArgSize(strlen(unknownArg)); |
| 1298 | // -> refuse suggestions for long args to prevent huge memory allocation for Damerau-Levenshtein algo |
| 1299 | if (unknownArgSize > 16) { |
| 1300 | return stringcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).(); |
| 1301 | } |
| 1302 | // -> remove dashes since argument names internally don't have them |
| 1303 | if (unknownArgSize >= 2 && unknownArg[0] == '-' && unknownArg[1] == '-') { |
| 1304 | unknownArg += 2; |
| 1305 | unknownArgSize -= 2; |
| 1306 | } |
| 1307 | |
| 1308 | // find best suggestions limiting the results to 2 |
| 1309 | multisetcxx . . $ std/multiset#<ArgumentSuggestioncxx . . $ CppUtilities/ArgumentSuggestion#> bestSuggestionscxx . . $ std/multiset#multiset(49f6e7a06ebc5aa8).; |
| 1310 | // -> consider relevant arguments |
| 1311 | for (const Argumentcxx . . $ CppUtilities/Argument# *const arg : completionInfo.relevantArgscxx . . $ CppUtilities/ArgumentCompletionInfo#relevantArgs.) { |
| 1312 | ArgumentSuggestioncxx . . $ CppUtilities/ArgumentSuggestion#ArgumentSuggestion(12d7fb8e6b484263).(unknownArg, unknownArgSize, arg->namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).(), !arg->denotesOperationcxx . . $ CppUtilities/Argument#denotesOperation(50ce9a9e25b4a850).()).addTocxx . . $ CppUtilities/ArgumentSuggestion#addTo(2da8636ff036a360).(bestSuggestions, 2); |
| 1313 | } |
| 1314 | // -> consider relevant values |
| 1315 | for (const Argumentcxx . . $ CppUtilities/Argument# *const arg : completionInfo.relevantPreDefinedValuescxx . . $ CppUtilities/ArgumentCompletionInfo#relevantPreDefinedValues.) { |
| 1316 | if (!arg->preDefinedCompletionValuescxx . . $ CppUtilities/Argument#preDefinedCompletionValues(a9f41ea0e82d88cf).()) { |
| 1317 | continue; |
| 1318 | } |
| 1319 | for (const char *i = arg->preDefinedCompletionValuescxx . . $ CppUtilities/Argument#preDefinedCompletionValues(a9f41ea0e82d88cf).(); *i; ++i) { |
| 1320 | const char *const wordStart(i); |
| 1321 | const char *wordEnd(wordStart + 1); |
| 1322 | for (; *wordEnd && *wordEnd != ' '; ++wordEnd) |
| 1323 | ; |
| 1324 | ArgumentSuggestioncxx . . $ CppUtilities/ArgumentSuggestion#ArgumentSuggestion(40163010065b39bd).(unknownArg, unknownArgSize, wordStart, static_cast<size_t>(wordEnd - wordStart), false).addTocxx . . $ CppUtilities/ArgumentSuggestion#addTo(2da8636ff036a360).(bestSuggestions, 2); |
| 1325 | i = wordEnd; |
| 1326 | } |
| 1327 | } |
| 1328 | |
| 1329 | // format suggestion |
| 1330 | stringcxx . . $ std/string# suggestionStrcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 1331 | if (const auto suggestionCount = bestSuggestions.sizecxx . . $ std/multiset#size(fa801f5ac5d26b4e).()) { |
| 1332 | // allocate memory |
| 1333 | size_t requiredSize = 15; |
| 1334 | for (const auto &suggestion : bestSuggestions) { |
| 1335 | requiredSize += suggestion.suggestionSizecxx . . $ CppUtilities/ArgumentSuggestion#suggestionSize. + 2; |
| 1336 | if (suggestion.hasDashPrefixcxx . . $ CppUtilities/ArgumentSuggestion#hasDashPrefix.) { |
| 1337 | requiredSize += 2; |
| 1338 | } |
| 1339 | } |
| 1340 | suggestionStr.reservecxx . . $ std/__cxx11/basic_string#reserve(9dac5f4bebd06212).(requiredSize); |
| 1341 | |
| 1342 | // add each suggestion to end up with something like "Did you mean status (1), pause (3), cat (4), edit (5) or rescan-all (8)?" |
| 1343 | suggestionStr +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). "\nDid you mean "; |
| 1344 | size_t i = 0; |
| 1345 | for (const auto &suggestion : bestSuggestions) { |
| 1346 | if (++i == suggestionCount && suggestionCount != 1) { |
| 1347 | suggestionStr +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). " or "; |
| 1348 | } else if (i > 1) { |
| 1349 | suggestionStr +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). ", "; |
| 1350 | } |
| 1351 | if (suggestion.hasDashPrefixcxx . . $ CppUtilities/ArgumentSuggestion#hasDashPrefix.) { |
| 1352 | suggestionStr +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). "--"; |
| 1353 | } |
| 1354 | suggestionStr.appendcxx . . $ std/__cxx11/basic_string#append(4f422887dc0eafa2).(suggestion.suggestioncxx . . $ CppUtilities/ArgumentSuggestion#suggestion., suggestion.suggestionSizecxx . . $ CppUtilities/ArgumentSuggestion#suggestionSize.); |
| 1355 | } |
| 1356 | suggestionStr +=cxx . . $ std/__cxx11/basic_string#`operator+=`(63cc1ae870623930). '?'; |
| 1357 | } |
| 1358 | return suggestionStrcxx . . $ std/__cxx11/basic_string#basic_string(8f3aaafa33d05d0b).; |
| 1359 | } |
| 1360 | |
| 1361 | /*! |
| 1362 | * \brief Returns a copy of \a escaped with escaping characters removed. |
| 1363 | */ |
| 1364 | static stdcxx . . $ std/::stringcxx . . $ std/string# unescapecxx . . $ CppUtilities/unescape(6ccff4770ff7ddc3).(stdcxx . . $ std/::string_viewcxx . . $ std/string_view# escaped) |
| 1365 | { |
| 1366 | auto unescaped = stdcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).::stringcxx . . $ std/string#(); |
| 1367 | auto onEscaping = false; |
| 1368 | unescaped.reservecxx . . $ std/__cxx11/basic_string#reserve(9dac5f4bebd06212).(escaped.sizecxx . . $ std/basic_string_view#size(c9b1e749b64d5edc).()); |
| 1369 | for (const auto c : escaped) { |
| 1370 | if (!onEscaping && c == '\\') { |
| 1371 | onEscaping = true; |
| 1372 | } else { |
| 1373 | unescaped +=cxx . . $ std/__cxx11/basic_string#`operator+=`(63cc1ae870623930). c; |
| 1374 | onEscaping = false; |
| 1375 | } |
| 1376 | } |
| 1377 | return unescapedcxx . . $ std/__cxx11/basic_string#basic_string(8f3aaafa33d05d0b).; |
| 1378 | } |
| 1379 | |
| 1380 | /*! |
| 1381 | * \brief Prints the bash completion for the specified arguments and the specified \a lastPath. |
| 1382 | * \remarks Arguments must have been parsed before with readSpecifiedArgs(). When calling this method, completionMode must |
| 1383 | * be set to true. |
| 1384 | */ |
| 1385 | void ArgumentParsercxx . . $ CppUtilities/ArgumentParser#::printBashCompletioncxx . . $ CppUtilities/ArgumentParser#printBashCompletion(34b204d995c4289d).(int argc, const char *const *argv, unsigned int currentWordIndex, const ArgumentReadercxx . . $ CppUtilities/ArgumentReader# &reader) const |
| 1386 | { |
| 1387 | // determine completion info and sort relevant arguments |
| 1388 | const auto completionInfo([&] { |
| 1389 | auto clutteredCompletionInfo(determineCompletionInfocxx . . $ CppUtilities/ArgumentParser#determineCompletionInfo(a82f731a26a5c72e).(argc, argv, currentWordIndex, reader)); |
| 1390 | clutteredCompletionInfo.relevantArgscxx . . $ CppUtilities/ArgumentCompletionInfo#relevantArgs..sortcxx . . $ std/__cxx11/list#sort(b07662a27bd562f9).(compareArgscxx . . $ CppUtilities/compareArgs(2a2599e577fc7676).); |
| 1391 | return clutteredCompletionInfo; |
| 1392 | }(cxx . . $ CppUtilities/ArgumentParser#printBashCompletion(34b204d995c4289d).$anonymous_type_1#`operator()`(eb622046ce0c4996).)); |
| 1393 | |
| 1394 | // read the "opening" (started but not finished argument denotation) |
| 1395 | const char *opening = nullptr; |
| 1396 | stringcxx . . $ std/string# compoundOpeningcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 1397 | size_t openingLen = 0, compoundOpeningStartLen = 0; |
| 1398 | unsigned char openingDenotationType = Valuecxx . . $ CppUtilities/Value.; |
| 1399 | if (argc && completionInfo.nextArgumentOrValuecxx . . $ CppUtilities/ArgumentCompletionInfo#nextArgumentOrValue.) { |
| 1400 | if (currentWordIndex < static_cast<unsigned int>(argc)) { |
| 1401 | opening = argv[currentWordIndex]; |
| 1402 | // For some reason completions for eg. "set --values disk=1 tag=a" are split so the |
| 1403 | // equation sign is an own argument ("set --values disk = 1 tag = a"). |
| 1404 | // This is not how values are treated by the argument parser. Hence the opening |
| 1405 | // must be joined again. In this case only the part after the equation sign needs to be |
| 1406 | // provided for completion so compoundOpeningStartLen is set to number of characters to skip. |
| 1407 | const size_t minCurrentWordIndex = (completionInfo.lastDetectedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArg. ? completionInfo.lastDetectedArgIndexcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArgIndex. : 0); |
| 1408 | if (currentWordIndex > minCurrentWordIndex && !strcmp(opening, "=")) { |
| 1409 | compoundOpening.reservecxx . . $ std/__cxx11/basic_string#reserve(9dac5f4bebd06212).(compoundOpeningStartLen = strlen(argv[--currentWordIndex]) + 1); |
| 1410 | compoundOpening =cxx . . $ std/__cxx11/basic_string#`operator=`(978ca1133b5f6e74). argv[currentWordIndex]; |
| 1411 | compoundOpening +=cxx . . $ std/__cxx11/basic_string#`operator+=`(63cc1ae870623930). '='; |
| 1412 | } else if (currentWordIndex > (minCurrentWordIndex + 1) && !strcmp(argv[currentWordIndex - 1], "=")) { |
| 1413 | compoundOpening.reservecxx . . $ std/__cxx11/basic_string#reserve(9dac5f4bebd06212).((compoundOpeningStartLen = strlen(argv[currentWordIndex -= 2]) + 1) + strlen(opening)); |
| 1414 | compoundOpening =cxx . . $ std/__cxx11/basic_string#`operator=`(978ca1133b5f6e74). argv[currentWordIndex]; |
| 1415 | compoundOpening +=cxx . . $ std/__cxx11/basic_string#`operator+=`(63cc1ae870623930). '='; |
| 1416 | compoundOpening +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). opening; |
| 1417 | } |
| 1418 | if (!compoundOpening.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) { |
| 1419 | opening = compoundOpening.datacxx . . $ std/__cxx11/basic_string#data(258ee1c9e0a18a5c).(); |
| 1420 | } |
| 1421 | } else { |
| 1422 | opening = *completionInfo.lastSpecifiedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastSpecifiedArg.; |
| 1423 | } |
| 1424 | if (*opening == '-') { |
| 1425 | ++opening; |
| 1426 | ++openingDenotationType; |
| 1427 | if (*opening == '-') { |
| 1428 | ++opening; |
| 1429 | ++openingDenotationType; |
| 1430 | } |
| 1431 | } |
| 1432 | openingLen = strlen(opening); |
| 1433 | } |
| 1434 | |
| 1435 | // print "COMPREPLY" bash array |
| 1436 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "COMPREPLY=("; |
| 1437 | // -> completions for parameter values |
| 1438 | bool noWhitespace = false; |
| 1439 | for (const Argumentcxx . . $ CppUtilities/Argument# *const arg : completionInfo.relevantPreDefinedValuescxx . . $ CppUtilities/ArgumentCompletionInfo#relevantPreDefinedValues.) { |
| 1440 | if (arg->valueCompletionBehaviourcxx . . $ CppUtilities/Argument#valueCompletionBehaviour(e66dc16b08d52b98).() &cxx . . $ CppUtilities/`operator&`(83f89e59cac566d1). ValueCompletionBehaviorcxx . . $ CppUtilities/ValueCompletionBehavior#::InvokeCallbackcxx . . $ CppUtilities/ValueCompletionBehavior#InvokeCallback. && arg->m_callbackFunctioncxx . . $ CppUtilities/Argument#m_callbackFunction.) { |
| 1441 | arg->m_callbackFunctioncxx . . $ CppUtilities/Argument#m_callbackFunction.(cxx . . $ std/function#`operator()`(39e0826ffb540481).arg->isPresentcxx . . $ CppUtilities/Argument#isPresent(50ce9a9e25b4a850).() ? arg->m_occurrencescxx . . $ CppUtilities/Argument#m_occurrences..frontcxx . . $ std/vector#front(af0004c3ce7cab93).() : ArgumentOccurrencecxx . . $ CppUtilities/ArgumentOccurrence#(Argumentcxx . . $ CppUtilities/Argument#::varValueCountcxx . . $ CppUtilities/Argument#varValueCount.)); |
| 1442 | } |
| 1443 | if (!arg->preDefinedCompletionValuescxx . . $ CppUtilities/Argument#preDefinedCompletionValues(a9f41ea0e82d88cf).()) { |
| 1444 | continue; |
| 1445 | } |
| 1446 | const bool appendEquationSign = arg->valueCompletionBehaviourcxx . . $ CppUtilities/Argument#valueCompletionBehaviour(e66dc16b08d52b98).() &cxx . . $ CppUtilities/`operator&`(83f89e59cac566d1). ValueCompletionBehaviorcxx . . $ CppUtilities/ValueCompletionBehavior#::AppendEquationSigncxx . . $ CppUtilities/ValueCompletionBehavior#AppendEquationSign.; |
| 1447 | if (argc && currentWordIndex <= completionInfo.lastSpecifiedArgIndexcxx . . $ CppUtilities/ArgumentCompletionInfo#lastSpecifiedArgIndex. && opening) { |
| 1448 | if (openingDenotationType != Valuecxx . . $ CppUtilities/Value.) { |
| 1449 | continue; |
| 1450 | } |
| 1451 | bool wordStart = true, ok = false, equationSignAlreadyPresent = false; |
| 1452 | size_t wordIndex = 0; |
| 1453 | for (const char *i = arg->preDefinedCompletionValuescxx . . $ CppUtilities/Argument#preDefinedCompletionValues(a9f41ea0e82d88cf).(), *end = opening + openingLen; *i;) { |
| 1454 | if (wordStart) { |
| 1455 | const char *i1 = i, *i2 = opening; |
| 1456 | for (; *i1 && i2 != end && *i1 == *i2; ++i1, ++i2) |
| 1457 | ; |
| 1458 | if ((ok = (i2 == end))) { |
| 1459 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\''; |
| 1460 | } |
| 1461 | wordStart = false; |
| 1462 | wordIndex = 0; |
| 1463 | } else if ((wordStart = (*i == ' ') || (*i == '\n'))) { |
| 1464 | equationSignAlreadyPresent = false; |
| 1465 | if (ok) { |
| 1466 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\'' <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' '; |
| 1467 | } |
| 1468 | ++i; |
| 1469 | continue; |
| 1470 | } else if (*i == '=') { |
| 1471 | equationSignAlreadyPresent = true; |
| 1472 | } |
| 1473 | if (!ok) { |
| 1474 | ++i; |
| 1475 | continue; |
| 1476 | } |
| 1477 | if (!compoundOpeningStartLen || wordIndex >= compoundOpeningStartLen) { |
| 1478 | if (*i == '\'') { |
| 1479 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "'\"'\"'"; |
| 1480 | } else { |
| 1481 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). *i; |
| 1482 | } |
| 1483 | } |
| 1484 | ++i; |
| 1485 | ++wordIndex; |
| 1486 | switch (*i) { |
| 1487 | case ' ': |
| 1488 | case '\n': |
| 1489 | case '\0': |
| 1490 | if (appendEquationSign && !equationSignAlreadyPresent) { |
| 1491 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '='; |
| 1492 | noWhitespace = true; |
| 1493 | equationSignAlreadyPresent = false; |
| 1494 | } |
| 1495 | if (*i == '\0') { |
| 1496 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\''; |
| 1497 | } |
| 1498 | } |
| 1499 | } |
| 1500 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' '; |
| 1501 | } else if (const char *i = arg->preDefinedCompletionValuescxx . . $ CppUtilities/Argument#preDefinedCompletionValues(a9f41ea0e82d88cf).()) { |
| 1502 | bool equationSignAlreadyPresent = false; |
| 1503 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\''; |
| 1504 | while (*i) { |
| 1505 | if (*i == '\'') { |
| 1506 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "'\"'\"'"; |
| 1507 | } else { |
| 1508 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). *i; |
| 1509 | } |
| 1510 | switch (*(++i)) { |
| 1511 | case '=': |
| 1512 | equationSignAlreadyPresent = true; |
| 1513 | break; |
| 1514 | case ' ': |
| 1515 | case '\n': |
| 1516 | case '\0': |
| 1517 | if (appendEquationSign && !equationSignAlreadyPresent) { |
| 1518 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '='; |
| 1519 | equationSignAlreadyPresent = false; |
| 1520 | } |
| 1521 | if (*i != '\0') { |
| 1522 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\''; |
| 1523 | if (*(++i)) { |
| 1524 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\''; |
| 1525 | } |
| 1526 | } |
| 1527 | } |
| 1528 | } |
| 1529 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\'' <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' '; |
| 1530 | } |
| 1531 | } |
| 1532 | // -> completions for further arguments |
| 1533 | for (const Argumentcxx . . $ CppUtilities/Argument# *const arg : completionInfo.relevantArgscxx . . $ CppUtilities/ArgumentCompletionInfo#relevantArgs.) { |
| 1534 | if (argc && currentWordIndex <= completionInfo.lastSpecifiedArgIndexcxx . . $ CppUtilities/ArgumentCompletionInfo#lastSpecifiedArgIndex. && opening) { |
| 1535 | switch (openingDenotationType) { |
| 1536 | case Valuecxx . . $ CppUtilities/Value.: |
| 1537 | if (!arg->denotesOperationcxx . . $ CppUtilities/Argument#denotesOperation(50ce9a9e25b4a850).() || strncmp(arg->namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).(), opening, openingLen)) { |
| 1538 | continue; |
| 1539 | } |
| 1540 | break; |
| 1541 | case Abbreviationcxx . . $ CppUtilities/Abbreviation.: |
| 1542 | break; |
| 1543 | case FullNamecxx . . $ CppUtilities/FullName.: |
| 1544 | if (strncmp(arg->namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).(), opening, openingLen)) { |
| 1545 | continue; |
| 1546 | } |
| 1547 | } |
| 1548 | } |
| 1549 | |
| 1550 | if (opening && openingDenotationType == Abbreviationcxx . . $ CppUtilities/Abbreviation. && !completionInfo.nextArgumentOrValuecxx . . $ CppUtilities/ArgumentCompletionInfo#nextArgumentOrValue.) { |
| 1551 | // TODO: add test for this case |
| 1552 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\'' <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '-' <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). opening <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). arg->abbreviationcxx . . $ CppUtilities/Argument#abbreviation(1b8b762cbef9c2c9).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\'' <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' '; |
| 1553 | } else if (completionInfo.lastDetectedArgcxx . . $ CppUtilities/ArgumentCompletionInfo#lastDetectedArg. && reader.argDenotationTypecxx . . $ CppUtilities/ArgumentReader#argDenotationType. == Abbreviationcxx . . $ CppUtilities/Abbreviation. && !completionInfo.nextArgumentOrValuecxx . . $ CppUtilities/ArgumentCompletionInfo#nextArgumentOrValue.) { |
| 1554 | if (reader.argvcxx . . $ CppUtilities/ArgumentReader#argv. == reader.endcxx . . $ CppUtilities/ArgumentReader#end.) { |
| 1555 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\'' <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). *(reader.argvcxx . . $ CppUtilities/ArgumentReader#argv. - 1) <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\'' <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' '; |
| 1556 | } |
| 1557 | } else if (arg->denotesOperationcxx . . $ CppUtilities/Argument#denotesOperation(50ce9a9e25b4a850).()) { |
| 1558 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\'' <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). arg->namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\'' <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' '; |
| 1559 | } else { |
| 1560 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\'' <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '-' <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '-' <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). arg->namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\'' <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' '; |
| 1561 | } |
| 1562 | } |
| 1563 | // -> completions for files and dirs |
| 1564 | // -> if there's already an "opening", determine the dir part and the file part |
| 1565 | auto actualDir = stdcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).::stringcxx . . $ std/string#(), actualFile = stdcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).::stringcxx . . $ std/string#(); |
| 1566 | auto haveFileOrDirCompletions = false; |
| 1567 | if (argc && currentWordIndex == completionInfo.lastSpecifiedArgIndexcxx . . $ CppUtilities/ArgumentCompletionInfo#lastSpecifiedArgIndex. && opening) { |
| 1568 | // the "opening" might contain escaped characters which need to be unescaped first |
| 1569 | const auto unescapedOpening = unescapecxx . . $ CppUtilities/unescape(6ccff4770ff7ddc3).(openingcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).); |
| 1570 | // determine the "directory" part |
| 1571 | auto dir = directorycxx . . $ CppUtilities/directory(fd626fc03107dd24).(unescapedOpening); |
| 1572 | if (dir.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) { |
| 1573 | actualDir =cxx . . $ std/__cxx11/basic_string#`operator=`(978ca1133b5f6e74). "."; |
| 1574 | } else { |
| 1575 | if (dir[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).0] == '\"' || dir[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).0] == '\'') { |
| 1576 | dir.erasecxx . . $ std/__cxx11/basic_string#erase(710c914f019a9041).(0, 1); |
| 1577 | } |
| 1578 | if (dir.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() > 1 && (dir[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).dir.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() - 2] == '\"' || dir[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).dir.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() - 2] == '\'')) { |
| 1579 | dir.erasecxx . . $ std/__cxx11/basic_string#erase(710c914f019a9041).(dir.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() - 2, 1); |
| 1580 | } |
| 1581 | actualDir =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(dir); |
| 1582 | } |
| 1583 | // determine the "file" part |
| 1584 | auto file = fileNamecxx . . $ CppUtilities/fileName(fd626fc03107dd24).(unescapedOpening); |
| 1585 | if (file[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).0] == '\"' || file[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).0] == '\'') { |
| 1586 | file.erasecxx . . $ std/__cxx11/basic_string#erase(710c914f019a9041).(0, 1); |
| 1587 | } |
| 1588 | if (file.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() > 1 && (file[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).file.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() - 2] == '\"' || file[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).file.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() - 2] == '\'')) { |
| 1589 | file.erasecxx . . $ std/__cxx11/basic_string#erase(710c914f019a9041).(file.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() - 2, 1); |
| 1590 | } |
| 1591 | actualFile =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(file); |
| 1592 | } |
| 1593 | |
| 1594 | // -> completion for files and dirs |
| 1595 | #ifdef CPP_UTILITIES_USE_STANDARD_FILESYSTEMcxx . . $ `<built-in>:484:9`! |
| 1596 | if (completionInfo.completeFilescxx . . $ CppUtilities/ArgumentCompletionInfo#completeFiles. || completionInfo.completeDirscxx . . $ CppUtilities/ArgumentCompletionInfo#completeDirs.) { |
| 1597 | try { |
| 1598 | const auto replace = "'"scxx . . $ std/literals/string_literals/`operator""s`(aa2a803d3c5b7a78)., with = "'\"'\"'"scxx . . $ std/literals/string_literals/`operator""s`(aa2a803d3c5b7a78).; |
| 1599 | const auto useActualDir = argc && currentWordIndex <= completionInfo.lastSpecifiedArgIndexcxx . . $ CppUtilities/ArgumentCompletionInfo#lastSpecifiedArgIndex. && opening; |
| 1600 | const auto dirEntries = [&] { |
| 1601 | filesystemcxx . . $ std/filesystem/::directory_iteratorcxx . . $ std/filesystem/__cxx11/directory_iterator# icxx . . $ std/filesystem/__cxx11/directory_iterator#directory_iterator(ced63f7c635d850d).; |
| 1602 | if (useActualDir) { |
| 1603 | i =cxx . . $ std/filesystem/__cxx11/directory_iterator#`operator=`(eec9fdd35117cd3e). filesystemcxx . . $ std/filesystem/::directory_iteratorcxx . . $ std/filesystem/__cxx11/directory_iterator#(actualDircxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d).); |
| 1604 | findAndReplacecxx . . $ CppUtilities/findAndReplace(24c06d9c65e079c1).(actualDir, replace, with); |
| 1605 | } else { |
| 1606 | i =cxx . . $ std/filesystem/__cxx11/directory_iterator#`operator=`(eec9fdd35117cd3e). filesystemcxx . . $ std/filesystem/::directory_iteratorcxx . . $ std/filesystem/__cxx11/directory_iterator#("."cxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d).); |
| 1607 | } |
| 1608 | return icxx . . $ std/filesystem/__cxx11/directory_iterator#directory_iterator(eb4127859234c0ea).; |
| 1609 | }(cxx . . $ CppUtilities/ArgumentParser#printBashCompletion(34b204d995c4289d).$anonymous_type_2#`operator()`(b95704f9eb5d5a45).); |
| 1610 | for (const auto &dirEntry : dirEntries) { |
| 1611 | if (!completionInfo.completeDirscxx . . $ CppUtilities/ArgumentCompletionInfo#completeDirs. && dirEntry.is_directorycxx . . $ std/filesystem/__cxx11/directory_entry#is_directory(50ce9a9e25b4a850).()) { |
| 1612 | continue; |
| 1613 | } |
| 1614 | if (!completionInfo.completeFilescxx . . $ CppUtilities/ArgumentCompletionInfo#completeFiles. && !dirEntry.is_directorycxx . . $ std/filesystem/__cxx11/directory_entry#is_directory(50ce9a9e25b4a850).()) { |
| 1615 | continue; |
| 1616 | } |
| 1617 | auto dirEntryName = dirEntry.pathcxx . . $ std/filesystem/__cxx11/directory_entry#path(3df3a2cdf6f4d926).().filenamecxx . . $ std/filesystem/__cxx11/path#filename(159787a050b29eb0).().stringcxx . . $ std/filesystem/__cxx11/path#string(219584694fe2b248).(); |
| 1618 | auto hasStartingQuote = false; |
| 1619 | if (useActualDir) { |
| 1620 | if (!startsWithcxx . . $ CppUtilities/startsWith(9c67b3b6cbcd0cef).(dirEntryName, actualFile)) { |
| 1621 | continue; |
| 1622 | } |
| 1623 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\''; |
| 1624 | hasStartingQuote = true; |
| 1625 | if (actualDir !=cxx . . $ std/`operator!=`(4b17aa87c9f300c6). ".") { |
| 1626 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(88df5bef833f7f83). actualDir; |
| 1627 | } |
| 1628 | } |
| 1629 | findAndReplacecxx . . $ CppUtilities/findAndReplace(24c06d9c65e079c1).(dirEntryName, replace, with); |
| 1630 | if (!hasStartingQuote) { |
| 1631 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\''; |
| 1632 | } |
| 1633 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(88df5bef833f7f83). dirEntryName <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\'' <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' '; |
| 1634 | haveFileOrDirCompletions = true; |
| 1635 | } |
| 1636 | } catch (const filesystemcxx . . $ std/filesystem/::filesystem_errorcxx . . $ std/filesystem/__cxx11/filesystem_error# &) { |
| 1637 | // ignore filesystem errors; there's no good way to report errors when printing bash completion |
| 1638 | } |
| 1639 | } |
| 1640 | #endif |
| 1641 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ')'; |
| 1642 | |
| 1643 | // ensure file or dir completions are formatted appropriately |
| 1644 | if (haveFileOrDirCompletions) { |
| 1645 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "; compopt -o filenames"; |
| 1646 | } |
| 1647 | |
| 1648 | // ensure trailing whitespace is omitted |
| 1649 | if (noWhitespace) { |
| 1650 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "; compopt -o nospace"; |
| 1651 | } |
| 1652 | |
| 1653 | coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 1654 | } |
| 1655 | |
| 1656 | /*! |
| 1657 | * \brief Checks the constrains of the specified \a args. |
| 1658 | * \remarks Checks the constraints of sub arguments, too. |
| 1659 | */ |
| 1660 | void ArgumentParsercxx . . $ CppUtilities/ArgumentParser#::checkConstraintscxx . . $ CppUtilities/ArgumentParser#checkConstraints(116237cab03ffd67).(const ArgumentVectorcxx . . $ CppUtilities/ArgumentVector# &args) |
| 1661 | { |
| 1662 | for (const Argumentcxx . . $ CppUtilities/Argument# *arg : args) { |
| 1663 | const auto occurrences = arg->occurrencescxx . . $ CppUtilities/Argument#occurrences(fe4d2d262d4164a8).(); |
| 1664 | if (arg->isParentPresentcxx . . $ CppUtilities/Argument#isParentPresent(50ce9a9e25b4a850).() && occurrences > arg->maxOccurrencescxx . . $ CppUtilities/Argument#maxOccurrences(fe4d2d262d4164a8).()) { |
| 1665 | throw ParseErrorcxx . . $ CppUtilities/ParseError#(argsToStringcxx . . $ CppUtilities/argsToString(2bd17df601864384).("The argument \"", arg->namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).(), "\" mustn't be specified more than ", arg->maxOccurrencescxx . . $ CppUtilities/Argument#maxOccurrences(fe4d2d262d4164a8).(), |
| 1666 | (arg->maxOccurrencescxx . . $ CppUtilities/Argument#maxOccurrences(fe4d2d262d4164a8).() == 1 ? " time." : " times."))); |
| 1667 | } |
| 1668 | if (arg->isParentPresentcxx . . $ CppUtilities/Argument#isParentPresent(50ce9a9e25b4a850).() && occurrences < arg->minOccurrencescxx . . $ CppUtilities/Argument#minOccurrences(fe4d2d262d4164a8).()) { |
| 1669 | throw ParseErrorcxx . . $ CppUtilities/ParseError#(argsToStringcxx . . $ CppUtilities/argsToString(2bd17df601864384).("The argument \"", arg->namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).(), "\" must be specified at least ", arg->minOccurrencescxx . . $ CppUtilities/Argument#minOccurrences(fe4d2d262d4164a8).(), |
| 1670 | (arg->minOccurrencescxx . . $ CppUtilities/Argument#minOccurrences(fe4d2d262d4164a8).() == 1 ? " time." : " times."))); |
| 1671 | } |
| 1672 | Argumentcxx . . $ CppUtilities/Argument# *conflictingArgument = nullptr; |
| 1673 | if (arg->isMainArgumentcxx . . $ CppUtilities/Argument#isMainArgument(50ce9a9e25b4a850).()) { |
| 1674 | if (!arg->isCombinablecxx . . $ CppUtilities/Argument#isCombinable(50ce9a9e25b4a850).() && arg->isPresentcxx . . $ CppUtilities/Argument#isPresent(50ce9a9e25b4a850).()) { |
| 1675 | conflictingArgument = firstPresentUncombinableArgcxx . . $ CppUtilities/firstPresentUncombinableArg(90bfa07d5099c83e).(m_mainArgscxx . . $ CppUtilities/ArgumentParser#m_mainArgs., arg); |
| 1676 | } |
| 1677 | } else { |
| 1678 | conflictingArgument = arg->conflictsWithArgumentcxx . . $ CppUtilities/Argument#conflictsWithArgument(cb6a3fc127670316).(); |
| 1679 | } |
| 1680 | if (conflictingArgument) { |
| 1681 | throw ParseErrorcxx . . $ CppUtilities/ParseError#(argsToStringcxx . . $ CppUtilities/argsToString(2bd17df601864384).("The argument \"", conflictingArgument->namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).(), "\" can not be combined with \"", arg->namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).(), "\".")); |
| 1682 | } |
| 1683 | for (size_t i = 0; i != occurrences; ++i) { |
| 1684 | if (arg->allRequiredValuesPresentcxx . . $ CppUtilities/Argument#allRequiredValuesPresent(2ff7c7de1baa6d0a).(i)) { |
| 1685 | continue; |
| 1686 | } |
| 1687 | stringstreamcxx . . $ std/stringstream# sscxx . . $ std/__cxx11/basic_stringstream#basic_stringstream(322f8929844464d3).(stringstreamcxx . . $ std/stringstream#::incxx . . $ std/ios_base#in. |cxx . . $ std/`operator|`(2dd9eb40323da8bf). stringstreamcxx . . $ std/stringstream#::outcxx . . $ std/ios_base#out.); |
| 1688 | ss <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Not all parameters for argument \"" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). arg->namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\" "; |
| 1689 | if (i) { |
| 1690 | ss <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " (" <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). (i + 1) <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " occurrence) "; |
| 1691 | } |
| 1692 | ss <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "provided. You have to provide the following parameters:"; |
| 1693 | size_t valueNamesPrint = 0; |
| 1694 | for (const auto &name : arg->m_valueNamescxx . . $ CppUtilities/Argument#m_valueNames.) { |
| 1695 | ss <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). name; |
| 1696 | ++valueNamesPrint; |
| 1697 | } |
| 1698 | if (arg->m_requiredValueCountcxx . . $ CppUtilities/Argument#m_requiredValueCount. != Argumentcxx . . $ CppUtilities/Argument#::varValueCountcxx . . $ CppUtilities/Argument#varValueCount.) { |
| 1699 | while (valueNamesPrint < arg->m_requiredValueCountcxx . . $ CppUtilities/Argument#m_requiredValueCount.) { |
| 1700 | ss <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\nvalue " <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). (++valueNamesPrint); |
| 1701 | } |
| 1702 | } |
| 1703 | throw ParseErrorcxx . . $ CppUtilities/ParseError#(ss.strcxx . . $ std/__cxx11/basic_stringstream#str(d33e1a6fd36255f7).()); |
| 1704 | } |
| 1705 | |
| 1706 | // check constraints of sub arguments recursively |
| 1707 | checkConstraintscxx . . $ CppUtilities/ArgumentParser#checkConstraints(116237cab03ffd67).(arg->m_subArgscxx . . $ CppUtilities/Argument#m_subArgs.); |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | /*! |
| 1712 | * \brief Invokes the callbacks for the specified \a args. |
| 1713 | * \remarks |
| 1714 | * - Checks the callbacks for sub arguments, too. |
| 1715 | * - Invokes the assigned callback methods for each occurrence of |
| 1716 | * the argument. |
| 1717 | */ |
| 1718 | void ArgumentParsercxx . . $ CppUtilities/ArgumentParser#::invokeCallbackscxx . . $ CppUtilities/ArgumentParser#invokeCallbacks(116237cab03ffd67).(const ArgumentVectorcxx . . $ CppUtilities/ArgumentVector# &args) |
| 1719 | { |
| 1720 | for (const Argumentcxx . . $ CppUtilities/Argument# *arg : args) { |
| 1721 | // invoke the callback for each occurrence of the argument |
| 1722 | if (arg->m_callbackFunctioncxx . . $ CppUtilities/Argument#m_callbackFunction.) { |
| 1723 | for (const auto &occurrence : arg->m_occurrencescxx . . $ CppUtilities/Argument#m_occurrences.) { |
| 1724 | arg->m_callbackFunctioncxx . . $ CppUtilities/Argument#m_callbackFunction.(cxx . . $ std/function#`operator()`(39e0826ffb540481).occurrence); |
| 1725 | } |
| 1726 | } |
| 1727 | // invoke the callbacks for sub arguments recursively |
| 1728 | invokeCallbackscxx . . $ CppUtilities/ArgumentParser#invokeCallbacks(116237cab03ffd67).(arg->m_subArgscxx . . $ CppUtilities/Argument#m_subArgs.); |
| 1729 | } |
| 1730 | } |
| 1731 | |
| 1732 | /*! |
| 1733 | * \brief Exits using the assigned function or std::exit(). |
| 1734 | */ |
| 1735 | void ArgumentParsercxx . . $ CppUtilities/ArgumentParser#::invokeExitcxx . . $ CppUtilities/ArgumentParser#invokeExit(d4f767463ce0a6b3).(int code) |
| 1736 | { |
| 1737 | if (m_exitFunctioncxx . . $ CppUtilities/ArgumentParser#m_exitFunction.) { |
| 1738 | m_exitFunctioncxx . . $ CppUtilities/ArgumentParser#m_exitFunction.(cxx . . $ std/function#`operator()`(39e0826ffb540481).code); |
| 1739 | return; |
| 1740 | } |
| 1741 | stdcxx . . $ std/::exit(code); |
| 1742 | } |
| 1743 | |
| 1744 | /*! |
| 1745 | * \class HelpArgument |
| 1746 | * \brief The HelpArgument class prints help information for an argument parser |
| 1747 | * when present (--help, -h). |
| 1748 | */ |
| 1749 | |
| 1750 | /*! |
| 1751 | * \brief Constructs a new help argument for the specified parser. |
| 1752 | */ |
| 1753 | HelpArgumentcxx . . $ CppUtilities/HelpArgument#::HelpArgumentcxx . . $ CppUtilities/HelpArgument#HelpArgument(d2dcd5df46dc3eee).(ArgumentParsercxx . . $ CppUtilities/ArgumentParser# &parser) |
| 1754 | : Argumentcxx . . $ CppUtilities/Argument#Argument(af3d03003c91f516).("help", 'h', "shows this information") |
| 1755 | { |
| 1756 | setCallbackcxx . . $ CppUtilities/Argument#setCallback(e4ee40b4f868025b).([cxx . . $ std/function#function(bdc3712e480e4d04).&parser](const ArgumentOccurrencecxx . . $ CppUtilities/ArgumentOccurrence# &) { |
| 1757 | CMD_UTILS_START_CONSOLEcxx . . $ `application/commandlineutils.h:35:9`!; |
| 1758 | parser.printHelpcxx . . $ CppUtilities/ArgumentParser#printHelp(490063bd7e6d8d5d).(coutcxx . . $ std/cout.); |
| 1759 | }); |
| 1760 | } |
| 1761 | |
| 1762 | /*! |
| 1763 | * \class OperationArgument |
| 1764 | * \brief The OperationArgument class is an Argument where denotesOperation() is true by default. |
| 1765 | */ |
| 1766 | |
| 1767 | /*! |
| 1768 | * \class ConfigValueArgument |
| 1769 | * \brief The ConfigValueArgument class is an Argument where setCombinable() is true by default. |
| 1770 | * \sa ConfigValueArgument::ConfigValueArgument() |
| 1771 | */ |
| 1772 | |
| 1773 | /*! |
| 1774 | * \class NoColorArgument |
| 1775 | * \brief The NoColorArgument class allows to specify whether use of escape codes or similar technique to provide formatted output |
| 1776 | * on the terminal should be enabled/disabled. |
| 1777 | * |
| 1778 | * This argument will either prevent or explicitly allow the use of escape codes or similar technique to provide formatted output |
| 1779 | * on the terminal. More explicitly, the argument will always allow to negate the default value of EscapeCodes::enabled which can be |
| 1780 | * configured at build time by setting the CMake variable ENABLE_ESCAPE_CODES_BY_DEFAULT. |
| 1781 | * |
| 1782 | * \remarks |
| 1783 | * - Only the first instance is considered for actually altering the value of EscapeCodes::enabled so it makes no sense to |
| 1784 | * instantiate this class multiple times. |
| 1785 | * - It is ensure that EscapeCodes::enabled will be set before any callback functions are invoked and even in the error case (if |
| 1786 | * the error doesn't prevent the argument from being detected). Hence this feature is implemented via NoColorArgument::apply() |
| 1787 | * rather than the usual callback mechanism. |
| 1788 | * |
| 1789 | * \sa NoColorArgument::NoColorArgument(), EscapeCodes::enabled |
| 1790 | */ |
| 1791 | |
| 1792 | /*! |
| 1793 | * \brief Constructs a new NoColorArgument argument. |
| 1794 | * \remarks This will also set EscapeCodes::enabled to the value of the environment variable ENABLE_ESCAPE_CODES. |
| 1795 | */ |
| 1796 | NoColorArgumentcxx . . $ CppUtilities/NoColorArgument#::NoColorArgumentcxx . . $ CppUtilities/NoColorArgument#NoColorArgument(49f6e7a06ebc5aa8).() |
| 1797 | #ifdef CPP_UTILITIES_ESCAPE_CODES_ENABLED_BY_DEFAULTcxx . . $ `<built-in>:485:9`! |
| 1798 | : Argumentcxx . . $ CppUtilities/Argument#Argument(af3d03003c91f516).("no-color", '\0', "disables formatted/colorized output") |
| 1799 | #else |
| 1800 | : Argument("enable-color", '\0', "enables formatted/colorized output") |
| 1801 | #endif |
| 1802 | { |
| 1803 | setCombinablecxx . . $ CppUtilities/Argument#setCombinable(b45ddcbc8423892c).(true); |
| 1804 | |
| 1805 | // set the environment variable (not directly used and just assigned for printing help) |
| 1806 | setEnvironmentVariablecxx . . $ CppUtilities/Argument#setEnvironmentVariable(85c52e162fed56f9).("ENABLE_ESCAPE_CODES"); |
| 1807 | |
| 1808 | // initialize EscapeCodes::enabled from environment variable |
| 1809 | const auto escapeCodesEnabled = isEnvVariableSetcxx . . $ CppUtilities/isEnvVariableSet(398a73c3631942a).(environmentVariablecxx . . $ CppUtilities/Argument#environmentVariable(a9f41ea0e82d88cf).()); |
| 1810 | if (escapeCodesEnabled.has_valuecxx . . $ std/optional#has_value(3482b152b9333168).()) { |
| 1811 | EscapeCodescxx . . $ CppUtilities/EscapeCodes/::enabledcxx . . $ CppUtilities/EscapeCodes/enabled. = escapeCodesEnabled.valuecxx . . $ std/optional#value(8cf0592b1484bc82).(); |
| 1812 | } |
| 1813 | } |
| 1814 | |
| 1815 | /*! |
| 1816 | * \brief Sets EscapeCodes::enabled according to the presence of the first instantiation of NoColorArgument. |
| 1817 | */ |
| 1818 | void NoColorArgumentcxx . . $ CppUtilities/NoColorArgument#::applycxx . . $ CppUtilities/NoColorArgument#apply(83f5f38750778ac8).() const |
| 1819 | { |
| 1820 | if (isPresentcxx . . $ CppUtilities/Argument#isPresent(50ce9a9e25b4a850).()) { |
| 1821 | #ifdef CPP_UTILITIES_ESCAPE_CODES_ENABLED_BY_DEFAULTcxx . . $ `<built-in>:485:9`! |
| 1822 | EscapeCodescxx . . $ CppUtilities/EscapeCodes/::enabledcxx . . $ CppUtilities/EscapeCodes/enabled. = false; |
| 1823 | #else |
| 1824 | EscapeCodes::enabled = true; |
| 1825 | #endif |
| 1826 | } |
| 1827 | } |
| 1828 | |
| 1829 | /*! |
| 1830 | * \brief Throws a Failure for the current instance and the specified \a argumentPath. |
| 1831 | */ |
| 1832 | void ValueConversioncxx . . $ CppUtilities/ValueConversion/::Helpercxx . . $ CppUtilities/ValueConversion/Helper/::ArgumentValueConversionErrorcxx . . $ CppUtilities/ValueConversion/Helper/ArgumentValueConversionError#::throwFailurecxx . . $ CppUtilities/ValueConversion/Helper/ArgumentValueConversionError#throwFailure(66bba89efa4d5a8c).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<Argumentcxx . . $ CppUtilities/Argument# *> &argumentPath) const |
| 1833 | { |
| 1834 | throw ParseErrorcxx . . $ CppUtilities/ParseError#(argumentPath.emptycxx . . $ std/vector#empty(3482b152b9333168).() |
| 1835 | ? argsToStringcxx . . $ CppUtilities/argsToString(2bd17df601864384).("Conversion of top-level value \"", valueToConvertcxx . . $ CppUtilities/ValueConversion/Helper/ArgumentValueConversionError#valueToConvert., "\" to type \"", targetTypeNamecxx . . $ CppUtilities/ValueConversion/Helper/ArgumentValueConversionError#targetTypeName., "\" failed: ", errorMessagecxx . . $ CppUtilities/ValueConversion/Helper/ArgumentValueConversionError#errorMessage.) |
| 1836 | : argsToStringcxx . . $ CppUtilities/argsToString(2bd17df601864384).("Conversion of value \"", valueToConvertcxx . . $ CppUtilities/ValueConversion/Helper/ArgumentValueConversionError#valueToConvert., "\" (for argument --", argumentPath.backcxx . . $ std/vector#back(af0004c3ce7cab93).()->namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).(), ") to type \"", |
| 1837 | targetTypeNamecxx . . $ CppUtilities/ValueConversion/Helper/ArgumentValueConversionError#targetTypeName., "\" failed: ", errorMessagecxx . . $ CppUtilities/ValueConversion/Helper/ArgumentValueConversionError#errorMessage.)); |
| 1838 | } |
| 1839 | |
| 1840 | /*! |
| 1841 | * \brief Throws a Failure for insufficient number of values. |
| 1842 | */ |
| 1843 | void ArgumentOccurrencecxx . . $ CppUtilities/ArgumentOccurrence#::throwNumberOfValuesNotSufficientcxx . . $ CppUtilities/ArgumentOccurrence#throwNumberOfValuesNotSufficient(cf8bf0a838713cc4).(unsigned long valuesToConvert) const |
| 1844 | { |
| 1845 | throw ParseErrorcxx . . $ CppUtilities/ParseError#(pathcxx . . $ CppUtilities/ArgumentOccurrence#path..emptycxx . . $ std/vector#empty(3482b152b9333168).() |
| 1846 | ? argsToStringcxx . . $ CppUtilities/argsToString(2bd17df601864384).("Expected ", valuesToConvert, " top-level values to be present but only ", valuescxx . . $ CppUtilities/ArgumentOccurrence#values..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(), " have been specified.") |
| 1847 | : argsToStringcxx . . $ CppUtilities/argsToString(2bd17df601864384).("Expected ", valuesToConvert, " values for argument --", pathcxx . . $ CppUtilities/ArgumentOccurrence#path..backcxx . . $ std/vector#back(af0004c3ce7cab93).()->namecxx . . $ CppUtilities/Argument#name(a9f41ea0e82d88cf).(), " to be present but only ", valuescxx . . $ CppUtilities/ArgumentOccurrence#values..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(), |
| 1848 | " have been specified.")); |
| 1849 | } |
| 1850 | |
| 1851 | } // namespace CppUtilities |