addOption('output', 'o', InputOption::VALUE_OPTIONAL, 'Output file path', base_path('permissions.json')); } /** * 执行命令 * * @param InputInterface $input * @param OutputInterface $output * @return int */ protected function execute(InputInterface $input, OutputInterface $output): int { $outputPath = $input->getOption('output'); $output->writeln('开始收集权限...'); try { /** @var MetadataCollectorService $collector */ $collector = Container::make(MetadataCollectorService::class); $permissions = $collector->collect(); // 导出为 JSON 文件 $success = $collector->exportToJson($outputPath); if ($success) { $output->writeln(sprintf('权限收集完成,共收集到 %d 个权限', count($permissions))); $output->writeln(sprintf('权限列表已导出到:%s', $outputPath)); return Command::SUCCESS; } else { $output->writeln('权限收集失败:无法写入文件'); return Command::FAILURE; } } catch (\Exception $e) { $output->writeln('权限收集失败:' . $e->getMessage() . ''); $output->writeln('错误堆栈:' . $e->getTraceAsString() . ''); return Command::FAILURE; } } }