From 7167ce41b61d2ba2cdb526777a4233eb84a3b66a Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Sat, 6 Dec 2014 17:33:25 -0500 Subject: Imported Upstream version 2.99.6 --- SQLiteStudio3/sqlitestudiocli/clicommandsyntax.h | 97 ++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 SQLiteStudio3/sqlitestudiocli/clicommandsyntax.h (limited to 'SQLiteStudio3/sqlitestudiocli/clicommandsyntax.h') diff --git a/SQLiteStudio3/sqlitestudiocli/clicommandsyntax.h b/SQLiteStudio3/sqlitestudiocli/clicommandsyntax.h new file mode 100644 index 0000000..adf88d2 --- /dev/null +++ b/SQLiteStudio3/sqlitestudiocli/clicommandsyntax.h @@ -0,0 +1,97 @@ +#ifndef CLICOMMANDSYNTAX_H +#define CLICOMMANDSYNTAX_H + +#include +#include +#include + +class CliCommandSyntax +{ + public: + CliCommandSyntax(); + ~CliCommandSyntax(); + + void addArgument(int id, const QString& name, bool mandatory = true); + void addStrictArgument(int id, const QStringList& values, bool mandatory = true); + void addAlternatedArgument(int id, const QStringList& names, bool mandatory = true); + void addOptionShort(int id, const QString& shortName); + void addOptionLong(int id, const QString& longName); + void addOption(int id, const QString& shortName, const QString& longName); + void addOptionWithArgShort(int id, const QString& shortName, const QString& argName); + void addOptionWithArgLong(int id, const QString& longName, const QString& argName); + void addOptionWithArg(int id, const QString& shortName, const QString& longName, const QString& argName); + + bool parse(const QStringList& args); + QString getErrorText() const; + QStringList getStrictArgumentCandidates(); + QList getRegularArgumentCandidates(); + + void addAlias(const QString& alias); + QStringList getAliases() const; + + QString getSyntaxDefinition() const; + QString getSyntaxDefinition(const QString& usedName) const; + + bool isArgumentSet(int id) const; + QString getArgument(int id) const; + + bool isOptionSet(int id) const; + QString getOptionValue(int id) const; + + QString getName() const; + void setName(const QString& value); + + bool getStrictArgumentCount() const; + void setStrictArgumentCount(bool value); + + private: + struct Argument + { + enum Type + { + REGULAR, + STRICT, + ALTERNATED + }; + + int id; + QStringList names; + Type type = REGULAR; + bool mandatory = true; + bool defined = false; + QString value; + }; + + struct Option + { + int id; + QString shortName; + QString longName; + QString argName; + bool requested = false; + QString value; + }; + + bool parseArg(const QString& arg); + bool parseOpt(const QString& arg, const QStringList& args, int& argIdx); + int requiredArguments() const; + void checkNewArgument(bool mandatory); + Argument* addArgumentInternal(int id, const QStringList& names, bool mandatory, Argument::Type type); + Option* addOptionInternal(int id, const QString& shortName, const QString& longName, const QString& argName); + + int argPosition = 0; + QString parsingErrorText; + bool strictArgumentCount = true; + bool pastOptions = false; + QString name; + QStringList aliases; + QList arguments; + QHash argumentMap; + QList options; + Option* lastParsedOption = nullptr; + QHash optionMap; + QHash optionsShortNameMap; + QHash optionsLongNameMap; +}; + +#endif // CLICOMMANDSYNTAX_H -- cgit v1.2.3