IntegrationShell.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * IntegrationShell file
  4. *
  5. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  6. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  7. *
  8. * Licensed under The MIT License
  9. * For full copyright and license information, please see the LICENSE.txt
  10. * Redistributions of files must retain the above copyright notice
  11. *
  12. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  13. * @link http://cakephp.org CakePHP(tm) Project
  14. * @since 3.5.0
  15. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  16. */
  17. /**
  18. * IntegrationShell
  19. */
  20. namespace TestApp\Shell;
  21. use Cake\Console\ConsoleOptionParser;
  22. use Cake\Console\Shell;
  23. class IntegrationShell extends Shell
  24. {
  25. /**
  26. * Option parser
  27. *
  28. * @return ConsoleOptionParser
  29. */
  30. public function getOptionParser()
  31. {
  32. $parser = new ConsoleOptionParser();
  33. $argAndOptionParser = (new ConsoleOptionParser())
  34. ->addArgument('arg', [
  35. 'required' => true
  36. ])
  37. ->addOption('opt', [
  38. 'short' => 'o'
  39. ]);
  40. $parser
  41. ->addSubcommand('argsAndOptions', [
  42. 'parser' => $argAndOptionParser
  43. ])
  44. ->addSubcommand('bridge');
  45. return $parser;
  46. }
  47. /**
  48. * Bridge of Death question
  49. *
  50. * @return void
  51. */
  52. public function bridge()
  53. {
  54. $name = $this->in('What is your name');
  55. if ($name !== 'cake') {
  56. $this->err('No!');
  57. $this->_stop(Shell::CODE_ERROR);
  58. }
  59. $color = $this->in('What is your favorite color?');
  60. if ($color !== 'blue') {
  61. $this->err('Wrong! <blink>Aaaahh</blink>');
  62. $this->_stop(Shell::CODE_ERROR);
  63. }
  64. $this->out('You may pass.');
  65. }
  66. /**
  67. * A sub command that requires an argument and has an option
  68. *
  69. * @return void
  70. */
  71. public function argsAndOptions()
  72. {
  73. $this->out('arg: ' . $this->args[0]);
  74. $this->out('opt: ' . $this->param('opt'));
  75. }
  76. }