|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * This file is part of CaptainHook |
| 5 | + * |
| 6 | + * (c) Sebastian Feldmann <sf@sebastian-feldmann.info> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace CaptainHook\App\Console\Command; |
| 13 | + |
| 14 | +use CaptainHook\App\Console\IOUtil; |
| 15 | +use CaptainHook\App\Runner\Config\Reader; |
| 16 | +use Symfony\Component\Console\Input\InputArgument; |
| 17 | +use Symfony\Component\Console\Input\InputInterface; |
| 18 | +use Symfony\Component\Console\Input\InputOption; |
| 19 | +use Symfony\Component\Console\Output\OutputInterface; |
| 20 | + |
| 21 | +/** |
| 22 | + * Command to display configuration information |
| 23 | + * |
| 24 | + * @package CaptainHook |
| 25 | + * @author Sebastian Feldmann <sf@sebastian-feldmann.info> |
| 26 | + * @link https://github.com/captainhookphp/captainhook |
| 27 | + * @since Class available since Release 5.24.0 |
| 28 | + */ |
| 29 | +class Info extends RepositoryAware |
| 30 | +{ |
| 31 | + /** |
| 32 | + * Configure the command |
| 33 | + * |
| 34 | + * @return void |
| 35 | + */ |
| 36 | + protected function configure(): void |
| 37 | + { |
| 38 | + parent::configure(); |
| 39 | + $this->setName('config:info') |
| 40 | + ->setAliases(['info']) |
| 41 | + ->setDescription('Displays information about the configuration') |
| 42 | + ->setHelp('Displays information about the configuration') |
| 43 | + ->addArgument('hook', InputArgument::OPTIONAL, 'Hook you want to investigate') |
| 44 | + ->addOption( |
| 45 | + 'list-actions', |
| 46 | + 'a', |
| 47 | + InputOption::VALUE_NONE, |
| 48 | + 'List all actions' |
| 49 | + ) |
| 50 | + ->addOption( |
| 51 | + 'list-conditions', |
| 52 | + 'p', |
| 53 | + InputOption::VALUE_NONE, |
| 54 | + 'List all conditions' |
| 55 | + ) |
| 56 | + ->addOption( |
| 57 | + 'list-options', |
| 58 | + 'o', |
| 59 | + InputOption::VALUE_NONE, |
| 60 | + 'List all options' |
| 61 | + ) |
| 62 | + ->addOption( |
| 63 | + 'list-config', |
| 64 | + 's', |
| 65 | + InputOption::VALUE_NONE, |
| 66 | + 'List all config settings' |
| 67 | + ) |
| 68 | + ->addOption( |
| 69 | + 'extensive', |
| 70 | + 'e', |
| 71 | + InputOption::VALUE_NONE, |
| 72 | + 'Show more detailed information' |
| 73 | + ); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Execute the command |
| 78 | + * |
| 79 | + * @param \Symfony\Component\Console\Input\InputInterface $input |
| 80 | + * @param \Symfony\Component\Console\Output\OutputInterface $output |
| 81 | + * @return int |
| 82 | + * @throws \CaptainHook\App\Exception\InvalidHookName |
| 83 | + * @throws \Exception |
| 84 | + */ |
| 85 | + protected function execute(InputInterface $input, OutputInterface $output): int |
| 86 | + { |
| 87 | + $io = $this->getIO($input, $output); |
| 88 | + $config = $this->createConfig($input, true, ['git-directory']); |
| 89 | + $repo = $this->createRepository(dirname($config->getGitDirectory())); |
| 90 | + |
| 91 | + $editor = new Reader($io, $config, $repo); |
| 92 | + $editor->setHook(IOUtil::argToString($input->getArgument('hook'))) |
| 93 | + ->display(Reader::OPT_ACTIONS, $input->getOption('list-actions')) |
| 94 | + ->display(Reader::OPT_CONDITIONS, $input->getOption('list-conditions')) |
| 95 | + ->display(Reader::OPT_OPTIONS, $input->getOption('list-options')) |
| 96 | + ->extensive($input->getOption('extensive')) |
| 97 | + ->run(); |
| 98 | + |
| 99 | + return 0; |
| 100 | + } |
| 101 | +} |
0 commit comments