ctkCLIModuleBlur2dImage.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. int main(int argc, char* argv[])
  20. {
  21. QCoreApplication app(argc, argv);
  22. // This is used by QSettings
  23. QCoreApplication::setOrganizationName("CommonTK");
  24. QCoreApplication::setApplicationName("CLIModuleBlur2dImage");
  25. ctkCommandLineParser parser;
  26. // Use Unix-style argument names
  27. parser.setArgumentPrefix("--", "-");
  28. // Add command line argument names
  29. parser.addArgument("help", "h", QVariant::Bool, "Show this help text");
  30. parser.addArgument("xml", "", QVariant::Bool, "Print a XML description of this modules command line interface");
  31. // Parse the command line arguments
  32. bool ok = false;
  33. QHash<QString, QVariant> parsedArgs = parser.parseArguments(QCoreApplication::arguments(), &ok);
  34. if (!ok)
  35. {
  36. QTextStream(stderr, QIODevice::WriteOnly) << "Error parsing arguments: "
  37. << parser.errorString() << "\n";
  38. return EXIT_FAILURE;
  39. }
  40. // Show a help message
  41. if (parsedArgs.contains("help") || parsedArgs.contains("h"))
  42. {
  43. QTextStream(stdout, QIODevice::WriteOnly) << parser.helpText();
  44. return EXIT_SUCCESS;
  45. }
  46. if (parsedArgs.contains("xml"))
  47. {
  48. QFile xmlDescription(":/ctkCLIModuleBlur2dImage.xml");
  49. xmlDescription.open(QIODevice::ReadOnly);
  50. QTextStream(stdout, QIODevice::WriteOnly) << xmlDescription.readAll();
  51. return EXIT_SUCCESS;
  52. }
  53. // Do something
  54. return EXIT_SUCCESS;
  55. }