IntegrationShell.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. ->addSubcommand('abort_shell');
  46. return $parser;
  47. }
  48. /**
  49. * Bridge of Death question
  50. *
  51. * @return void
  52. */
  53. public function bridge()
  54. {
  55. $name = $this->in('What is your name');
  56. if ($name !== 'cake') {
  57. $this->err('No!');
  58. $this->_stop(Shell::CODE_ERROR);
  59. }
  60. $color = $this->in('What is your favorite color?');
  61. if ($color !== 'blue') {
  62. $this->err('Wrong! <blink>Aaaahh</blink>');
  63. $this->_stop(Shell::CODE_ERROR);
  64. }
  65. $this->out('You may pass.');
  66. }
  67. /**
  68. * A sub command that requires an argument and has an option
  69. *
  70. * @return void
  71. */
  72. public function argsAndOptions()
  73. {
  74. $this->out('arg: ' . $this->args[0]);
  75. $this->out('opt: ' . $this->param('opt'));
  76. }
  77. /**
  78. * @throws \Cake\Console\Exception\StopException
  79. */
  80. public function abortShell()
  81. {
  82. $this->abort('Shell aborted');
  83. }
  84. }