|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright 2019 Google Inc. |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or modify it under |
| 7 | + * the terms of the GNU General Public License version 2 as published by the |
| 8 | + * Free Software Foundation. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
| 11 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 12 | + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
| 13 | + * License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License along |
| 16 | + * with this program; if not, write to the Free Software Foundation, Inc., 51 |
| 17 | + * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | + */ |
| 19 | + |
| 20 | +namespace Drupal\apigee_edge\Command; |
| 21 | + |
| 22 | +use Symfony\Component\Console\Input\InputArgument; |
| 23 | +use Symfony\Component\Console\Input\InputInterface; |
| 24 | +use Symfony\Component\Console\Input\InputOption; |
| 25 | +use Symfony\Component\Console\Output\OutputInterface; |
| 26 | + |
| 27 | +/** |
| 28 | + * Developer synchronization command class for Drupal Console. |
| 29 | + * |
| 30 | + * @Drupal\Console\Annotations\DrupalCommand ( |
| 31 | + * extension="apigee_edge", |
| 32 | + * extensionType="module" |
| 33 | + * ) |
| 34 | + */ |
| 35 | +class CreateEdgeRoleCommand extends CommandBase { |
| 36 | + |
| 37 | + /** |
| 38 | + * {@inheritdoc} |
| 39 | + */ |
| 40 | + protected function configure() { |
| 41 | + $this |
| 42 | + ->setName('apigee_edge:role:create') |
| 43 | + ->setDescription($this->trans('commands.apigee_edge.role.create.description')) |
| 44 | + ->setHelp('commands.apigee_edge.role.create.help') |
| 45 | + ->addArgument( |
| 46 | + 'org', |
| 47 | + InputArgument::REQUIRED, |
| 48 | + $this->trans('commands.apigee_edge.role.create.arguments.org') |
| 49 | + ) |
| 50 | + ->addArgument( |
| 51 | + 'email', |
| 52 | + InputArgument::REQUIRED, |
| 53 | + $this->trans('commands.apigee_edge.role.create.arguments.email') |
| 54 | + ) |
| 55 | + ->addOption( |
| 56 | + 'password', |
| 57 | + 'p', |
| 58 | + InputArgument::OPTIONAL, |
| 59 | + $this->trans('commands.apigee_edge.role.create.options.password') |
| 60 | + ) |
| 61 | + ->addOption( |
| 62 | + 'base-url', |
| 63 | + 'b', |
| 64 | + InputArgument::OPTIONAL, |
| 65 | + $this->trans('commands.apigee_edge.role.create.options.base-url') |
| 66 | + ) |
| 67 | + ->addOption( |
| 68 | + 'role-name', |
| 69 | + 'r', |
| 70 | + InputArgument::OPTIONAL, |
| 71 | + $this->trans('commands.apigee_edge.role.create.options.role-name') |
| 72 | + )->addOption( |
| 73 | + 'force', |
| 74 | + 'f', |
| 75 | + InputOption::VALUE_NONE, |
| 76 | + $this->trans('commands.apigee_edge.role.create.options.force') |
| 77 | + ); |
| 78 | + |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * {@inheritdoc} |
| 83 | + */ |
| 84 | + public function interact(InputInterface $input, OutputInterface $output) { |
| 85 | + $this->setupIo($input, $output); |
| 86 | + $password = $input->getOption('password'); |
| 87 | + if (!$password) { |
| 88 | + $password = $this->getIo()->askHidden( |
| 89 | + $this->trans('commands.apigee_edge.role.create.questions.password') |
| 90 | + ); |
| 91 | + $input->setOption('password', $password); |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * {@inheritdoc} |
| 97 | + */ |
| 98 | + public function execute(InputInterface $input, OutputInterface $output) { |
| 99 | + $this->setupIo($input, $output); |
| 100 | + $org = $input->getArgument('org'); |
| 101 | + $email = $input->getArgument('email'); |
| 102 | + $password = $input->getOption('password'); |
| 103 | + $base_url = $input->getOption('base-url'); |
| 104 | + $role_name = $input->getOption('role-name'); |
| 105 | + $force = $input->getOption('force'); |
| 106 | + |
| 107 | + $this->cliService->createEdgeRoleForDrupal($this->getIo(), 't', $org, $email, $password, $base_url, $role_name, $force); |
| 108 | + } |
| 109 | + |
| 110 | +} |
0 commit comments