ApplicationParameters.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <source/ApplicationParameters.h>
  9. #include <AzCore/Settings/CommandLine.h>
  10. #include <AzToolsFramework/Application/ToolsApplication.h>
  11. namespace PythonBindingsExample
  12. {
  13. void ApplicationParameters::ShowHelp()
  14. {
  15. constexpr const char* helpText =
  16. R"(PythonBindingsExample - An example of how to bind the Behavior Context in a simple Tools Application
  17. PythonBindingsExample.exe --file path/to/file.py --arg one --arg two
  18. --help Prints the help text
  19. --verbose (v) Uses verbose output
  20. --file (f) Execute this Python script file
  21. --arg (a) Any number of args sent to the Python script
  22. --interactive (i) Run in interactive mode after file and/or statement (note: enable --verbose to get Python output)
  23. --statement (s) Run Python string statement)";
  24. puts(helpText);
  25. }
  26. bool ApplicationParameters::Parse(const AzFramework::CommandLine* commandLine)
  27. {
  28. if (commandLine->empty())
  29. {
  30. ShowHelp();
  31. return false;
  32. }
  33. for (auto&& switchItem : *commandLine)
  34. {
  35. if (switchItem.m_option == "help")
  36. {
  37. ShowHelp();
  38. return false;
  39. }
  40. else if (switchItem.m_option.starts_with('v'))
  41. {
  42. m_verbose = true;
  43. }
  44. else if (switchItem.m_option.starts_with('f'))
  45. {
  46. m_pythonFilename = switchItem.m_value;
  47. }
  48. else if (switchItem.m_option.starts_with('a'))
  49. {
  50. m_pythonArgs.push_back(switchItem.m_value);
  51. }
  52. else if (switchItem.m_option.starts_with('s'))
  53. {
  54. m_pythonStatement = switchItem.m_value;
  55. }
  56. else if (switchItem.m_option.starts_with('i'))
  57. {
  58. m_interactiveMode = true;
  59. }
  60. else if (switchItem.m_option.starts_with("regset"))
  61. {
  62. // skip
  63. }
  64. else
  65. {
  66. AZ_Warning("python_app", false, "Unknown switch %s \n", switchItem.m_option.c_str());
  67. }
  68. }
  69. return true;
  70. }
  71. }