setDescription('Generate single-use backup codes') ->addArgument('count', InputArgument::OPTIONAL, 'Number of codes to generate', 10); } /** @throws InvalidArgumentException */ protected function execute(InputInterface $input, OutputInterface $output): int { /* since Kernel::terminate() does not get called, we must boot and persist explicitly */ $this->persistCache->boot(); $count = (int) $input->getArgument('count'); if ($count < 1) { throw new ConsoleInvalidArgumentException('Count must be a positive integer.'); } $codes = $this->manager->generate($count); foreach ($codes as $code) { $output->writeln($code); } $this->persistCache->persist(); return Command::SUCCESS; } }