%command.name% command allows you to disable an existing API key, via its name or the plain-text key. If no arguments are provided, you will be prompted to select one of the existing non-disabled API keys. %command.full_name% You can optionally pass the API key name to be disabled. In that case --by-name is also required, to indicate the first argument is the API key name and not the plain-text key: %command.full_name% the_key_name --by-name You can pass the plain-text key to be disabled, but that is DEPRECATED. In next major version, the argument will always be assumed to be the name: %command.full_name% d6b6c60e-edcd-4e43-96ad-fa6b7014c143 HELP; $this ->setName(self::NAME) ->setDescription('Disables an API key by name or plain-text key (providing a plain-text key is DEPRECATED)') ->addArgument( 'keyOrName', InputArgument::OPTIONAL, 'The API key to disable. Pass `--by-name` to indicate this value is the name and not the key.', ) ->addOption( 'by-name', mode: InputOption::VALUE_NONE, description: 'Indicates the first argument is the API key name, not the plain-text key.', ) ->setHelp($help); } protected function interact(InputInterface $input, OutputInterface $output): void { $keyOrName = $input->getArgument('keyOrName'); if ($keyOrName === null) { $apiKeys = $this->apiKeyService->listKeys(enabledOnly: true); $name = (new SymfonyStyle($input, $output))->choice( 'What API key do you want to disable?', map($apiKeys, static fn (ApiKey $apiKey) => $apiKey->name), ); $input->setArgument('keyOrName', $name); $input->setOption('by-name', true); } } protected function execute(InputInterface $input, OutputInterface $output): int { $keyOrName = $input->getArgument('keyOrName'); $byName = $input->getOption('by-name'); $io = new SymfonyStyle($input, $output); if (! $keyOrName) { $io->warning('An API key name was not provided.'); return ExitCode::EXIT_WARNING; } try { if ($byName) { $this->apiKeyService->disableByName($keyOrName); } else { $this->apiKeyService->disableByKey($keyOrName); } $io->success(sprintf('API key "%s" properly disabled', $keyOrName)); return ExitCode::EXIT_SUCCESS; } catch (InvalidArgumentException $e) { $io->error($e->getMessage()); return ExitCode::EXIT_FAILURE; } } }