ctkCmdLineModuleBlur2dImage.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  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. #include <ctkCommandLineParser.h>
  16. #include <QCoreApplication>
  17. #include <QTextStream>
  18. #include <QFile>
  19. #include <QDebug>
  20. #include <cstdlib>
  21. int main(int argc, char* argv[])
  22. {
  23. QCoreApplication app(argc, argv);
  24. // This is used by QSettings
  25. QCoreApplication::setOrganizationName("CommonTK");
  26. QCoreApplication::setApplicationName("CmdLineModuleBlur2dImage");
  27. ctkCommandLineParser parser;
  28. // Use Unix-style argument names
  29. parser.setArgumentPrefix("--", "-");
  30. // Add command line argument names
  31. parser.addArgument("help", "h", QVariant::Bool, "Show this help text");
  32. parser.addArgument("xml", "", QVariant::Bool, "Print a XML description of this modules command line interface");
  33. QTextStream out(stdout, QIODevice::WriteOnly);
  34. QTextStream err(stderr, QIODevice::WriteOnly);
  35. // Parse the command line arguments
  36. bool ok = false;
  37. QHash<QString, QVariant> parsedArgs = parser.parseArguments(QCoreApplication::arguments(), &ok);
  38. if (!ok)
  39. {
  40. err << "Error parsing arguments: " << parser.errorString() << "\n";
  41. return EXIT_FAILURE;
  42. }
  43. // Show a help message
  44. if (parsedArgs.contains("help") || parsedArgs.contains("h"))
  45. {
  46. out << parser.helpText();
  47. return EXIT_SUCCESS;
  48. }
  49. if (parsedArgs.contains("xml"))
  50. {
  51. QFile xmlDescription(":/ctkCmdLineModuleBlur2dImage.xml");
  52. xmlDescription.open(QIODevice::ReadOnly);
  53. out << xmlDescription.readAll();
  54. return EXIT_SUCCESS;
  55. }
  56. // Do something
  57. qDebug() << "Got parameter: " << QCoreApplication::arguments();
  58. return EXIT_SUCCESS;
  59. }