diff options
| author | 2014-12-06 17:33:25 -0500 | |
|---|---|---|
| committer | 2014-12-06 17:33:25 -0500 | |
| commit | 7167ce41b61d2ba2cdb526777a4233eb84a3b66a (patch) | |
| tree | a35c14143716e1f2c98f808c81f89426045a946f /SQLiteStudio3/sqlitestudiocli/clicommandsyntax.h | |
Imported Upstream version 2.99.6upstream/2.99.6
Diffstat (limited to 'SQLiteStudio3/sqlitestudiocli/clicommandsyntax.h')
| -rw-r--r-- | SQLiteStudio3/sqlitestudiocli/clicommandsyntax.h | 97 |
1 files changed, 97 insertions, 0 deletions
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 <QString>
+#include <QStringList>
+#include <QHash>
+
+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<int> 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<Argument*> arguments;
+ QHash<int,Argument*> argumentMap;
+ QList<Option*> options;
+ Option* lastParsedOption = nullptr;
+ QHash<int,Option*> optionMap;
+ QHash<QString,Option*> optionsShortNameMap;
+ QHash<QString,Option*> optionsLongNameMap;
+};
+
+#endif // CLICOMMANDSYNTAX_H
|
