trikRuntime
commandLineParser.h
Go to the documentation of this file.
1 /* Copyright 2015 CyberTech Labs Ltd.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License. */
14 
15 #pragma once
16 
17 #include <QtCore/QString>
18 #include <QtCore/QCoreApplication>
19 #include <QtCore/QHash>
20 #include <QtCore/QSet>
21 #include <QtCore/QStringList>
22 
23 namespace trikKernel {
24 
34 {
35 public:
37  void addApplicationDescription(const QString &description);
38 
40  void addPositionalArgument(const QString &name, const QString &description);
41 
44  void addOption(const QString &shortName, const QString &longName, const QString &description);
45 
48  void addFlag(const QString &shortName, const QString &longName, const QString &description);
49 
52  bool process(const QCoreApplication &app);
53 
55  void showHelp() const;
56 
58  QStringList positionalArgs() const;
59 
61  bool isSet(const QString &optionShortName) const;
62 
64  QString value(const QString &optionShortName) const;
65 
66 private:
67  QString mApplicationName;
68  QString mApplicationVersion;
69  QString mApplicationDescription;
70  QStringList mPositionalArgNames;
71  QStringList mPositionalArgDescriptions;
72  QStringList mPositionalArgValues;
73  QHash<QString, QString> mOptionDescriptions;
74  QHash<QString, QString> mOptionLongNames;
75  QHash<QString, QString> mOptionValues;
76  QHash<QString, QString> mFlagDescriptions;
77  QHash<QString, QString> mFlagLongNames;
78  QSet<QString> mSetFlags;
79 };
80 
81 }
Definition: analogSensor.h:23
bool isSet(const QString &optionShortName) const
Returns true, if option or flag appeared in command line.
Definition: commandLineParser.cpp:146
void showHelp() const
Shows application info and descriptions of all command line arguments.
Definition: commandLineParser.cpp:101
void addPositionalArgument(const QString &name, const QString &description)
Adds new positional argument with its description.
Definition: commandLineParser.cpp:26
QString value(const QString &optionShortName) const
Returns value of an option or an empty string if it is not set.
Definition: commandLineParser.cpp:151
bool process(const QCoreApplication &app)
Parse command line arguments of given application.
Definition: commandLineParser.cpp:44
void addOption(const QString &shortName, const QString &longName, const QString &description)
Add new option with short and long forms and descriptions.
Definition: commandLineParser.cpp:32
QStringList positionalArgs() const
Returns a list of positional arguments in order in which they appeared in command line...
Definition: commandLineParser.cpp:141
Parser of command-line parameters.
Definition: commandLineParser.h:33
void addFlag(const QString &shortName, const QString &longName, const QString &description)
Add new flag with short and long forms and descriptions.
Definition: commandLineParser.cpp:38
void addApplicationDescription(const QString &description)
Adds application description string.
Definition: commandLineParser.cpp:21