From fca19f265b1f6709173d4279a7e953c97469d8e2 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 11 Jan 2021 20:14:18 +0100 Subject: [PATCH] Removed duplicated lines in GenerateKeyCommand --- .../src/Command/Api/GenerateKeyCommand.php | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/module/CLI/src/Command/Api/GenerateKeyCommand.php b/module/CLI/src/Command/Api/GenerateKeyCommand.php index 37f0aaca..2dc91c51 100644 --- a/module/CLI/src/Command/Api/GenerateKeyCommand.php +++ b/module/CLI/src/Command/Api/GenerateKeyCommand.php @@ -22,21 +22,6 @@ use function sprintf; class GenerateKeyCommand extends Command { public const NAME = 'api-key:generate'; - private const HELP = <<%command.name% generates a new valid API key. - - %command.full_name% - - You can optionally set its expiration date with --expirationDate or -e: - - %command.full_name% --expirationDate 2020-01-01 - - You can also set roles to the API key: - - * Can interact with short URLs created with this API key: %command.full_name% --author-only - * Can interact with short URLs for one domain only: %command.full_name% --domain-only=example.com - * Both: %command.full_name% --author-only --domain-only=example.com - HELP; private ApiKeyServiceInterface $apiKeyService; private RoleResolverInterface $roleResolver; @@ -50,6 +35,24 @@ class GenerateKeyCommand extends Command protected function configure(): void { + $authorOnly = RoleResolverInterface::AUTHOR_ONLY_PARAM; + $domainOnly = RoleResolverInterface::DOMAIN_ONLY_PARAM; + $help = <<%command.name% generates a new valid API key. + + %command.full_name% + + You can optionally set its expiration date with --expirationDate or -e: + + %command.full_name% --expirationDate 2020-01-01 + + You can also set roles to the API key: + + * Can interact with short URLs created with this API key: %command.full_name% --{$authorOnly} + * Can interact with short URLs for one domain: %command.full_name% --{$domainOnly}=example.com + * Both: %command.full_name% --{$authorOnly} --{$domainOnly}=example.com + HELP; + $this ->setName(self::NAME) ->setDescription('Generates a new valid API key.') @@ -60,18 +63,18 @@ class GenerateKeyCommand extends Command 'The date in which the API key should expire. Use any valid PHP format.', ) ->addOption( - RoleResolverInterface::AUTHOR_ONLY_PARAM, + $authorOnly, 'a', InputOption::VALUE_NONE, sprintf('Adds the "%s" role to the new API key.', Role::AUTHORED_SHORT_URLS), ) ->addOption( - RoleResolverInterface::DOMAIN_ONLY_PARAM, + $domainOnly, 'd', InputOption::VALUE_REQUIRED, sprintf('Adds the "%s" role to the new API key, with the domain provided.', Role::DOMAIN_SPECIFIC), ) - ->setHelp(self::HELP); + ->setHelp($help); } protected function execute(InputInterface $input, OutputInterface $output): ?int @@ -82,7 +85,6 @@ class GenerateKeyCommand extends Command ...$this->roleResolver->determineRoles($input), ); - // TODO Print permissions that have been set $io = new SymfonyStyle($input, $output); $io->success(sprintf('Generated API key: "%s"', $apiKey->toString()));