From 1752cb62dc0bb8d7289745eb01abb6103089ed74 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Thu, 7 Apr 2011 16:07:55 +0300 Subject: [PATCH] GUI: Print command line help with -h and --help. --- gui/main.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/gui/main.cpp b/gui/main.cpp index fbc709744..30dcc246b 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -21,12 +21,21 @@ #include #include #include +#include +#include #include "mainwindow.h" #include "erroritem.h" +void ShowUsage(); +bool CheckArgs(const QStringList &args); + int main(int argc, char *argv[]) { QApplication app(argc, argv); + + if (!CheckArgs(app.arguments())) + return 0; + app.setWindowIcon(QIcon(":icon.png")); // Register this metatype that is used to transfer error info @@ -40,3 +49,25 @@ int main(int argc, char *argv[]) window.show(); return app.exec(); } + +// Check only arguments needing action before GUI is shown. +// Rest of the arguments are handled in MainWindow::HandleCLIParams() +bool CheckArgs(const QStringList &args) +{ + if (args.contains("-h") || args.contains("--help")) + { + ShowUsage(); + return false; + } + return true; +} + +void ShowUsage() +{ + std::cout << "Cppcheck GUI.\n\n"; + std::cout << "Syntax:\n"; + std::cout << " cppcheck-gui [OPTIONS] [files or paths]\n\n"; + std::cout << "Options:\n"; + std::cout << " -h, --help Print this help\n"; + std::cout << " -p Open given project file and start checking it\n"; +}