You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

qcommandlineparser.h 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2013 Laszlo Papp <lpapp@kde.org>
  4. ** Contact: http://www.qt.io/licensing/
  5. **
  6. ** This file is part of the QtCore module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL21$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see http://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at http://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 2.1 or version 3 as published by the Free
  20. ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
  21. ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
  22. ** following information to ensure the GNU Lesser General Public License
  23. ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
  24. ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  25. **
  26. ** As a special exception, The Qt Company gives you certain additional
  27. ** rights. These rights are described in The Qt Company LGPL Exception
  28. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  29. **
  30. ** $QT_END_LICENSE$
  31. **
  32. ****************************************************************************/
  33. #ifndef QCOMMANDLINEPARSER_H
  34. #define QCOMMANDLINEPARSER_H
  35. #include <QtCore/qstringlist.h>
  36. #include <QtCore/qcoreapplication.h>
  37. #include "qcommandlineoption.h"
  38. class QCommandLineParserPrivate;
  39. class QCoreApplication;
  40. class Q_CORE_EXPORT QCommandLineParser
  41. {
  42. Q_DECLARE_TR_FUNCTIONS(QCommandLineParser)
  43. public:
  44. QCommandLineParser();
  45. ~QCommandLineParser();
  46. enum SingleDashWordOptionMode {
  47. ParseAsCompactedShortOptions,
  48. ParseAsLongOptions
  49. };
  50. void setSingleDashWordOptionMode(SingleDashWordOptionMode parsingMode);
  51. bool addOption(const QCommandLineOption &commandLineOption);
  52. bool addOptions(const QList<QCommandLineOption> &options);
  53. QCommandLineOption addVersionOption();
  54. QCommandLineOption addHelpOption();
  55. void setApplicationDescription(const QString &description);
  56. QString applicationDescription() const;
  57. void addPositionalArgument(const QString &name, const QString &description, const QString &syntax = QString());
  58. void clearPositionalArguments();
  59. void process(const QStringList &arguments);
  60. void process(const QCoreApplication &app);
  61. bool parse(const QStringList &arguments);
  62. QString errorText() const;
  63. bool isSet(const QString &name) const;
  64. QString value(const QString &name) const;
  65. QStringList values(const QString &name) const;
  66. bool isSet(const QCommandLineOption &option) const;
  67. QString value(const QCommandLineOption &option) const;
  68. QStringList values(const QCommandLineOption &option) const;
  69. QStringList positionalArguments() const;
  70. QStringList optionNames() const;
  71. QStringList unknownOptionNames() const;
  72. void showVersion();
  73. void showHelp(int exitCode = 0);
  74. QString helpText() const;
  75. private:
  76. Q_DISABLE_COPY(QCommandLineParser)
  77. QCommandLineParserPrivate * const d;
  78. };
  79. #endif // QCOMMANDLINEPARSER_H