-void CliParser::addOption(const QString longName, const char shortName, const QString help, const QString def) {
- CliParserArg arg = CliParserArg(CliParserArg::CliArgOption, shortName, help, def);
- argsHash.insert(longName, arg);
- if(shortName) {
- if(!shortHash.contains(shortName)) shortHash.insert(shortName, argsHash.find(longName));
- else qWarning("Warning: shortName %c defined multiple times.", shortName);
+bool CliParser::addShortArg(const CliParserArg::CliArgType type, const char shortName, const QString &value) {
+ QString longName = lnameOfShortArg(shortName);
+ if(!longName.isNull()) {
+ if(type == CliParserArg::CliArgOption && argsHash.value(longName).type == type) {
+ argsHash[longName].value = escapedValue(value);
+ return true;
+ }
+ else if (type == CliParserArg::CliArgSwitch) {
+ if(argsHash.value(longName).type == type) {
+ argsHash[longName].boolValue = true;
+ return true;
+ }
+ // arg is an option but detected as a switch -> argument is missing
+ else {
+ qWarning().nospace() << "Warning: '" << shortName << "' is an option which needs an argument";
+ return false;
+ }
+ }