From 13b3e197eb1b4ff3250466a5f5201d9bc383b758 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Wed, 24 Jul 2024 11:47:19 +0200 Subject: [PATCH] always parse config-file ourselfs --- src/Supportive/Console/Application.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Supportive/Console/Application.php b/src/Supportive/Console/Application.php index a6ee744d..b40b887c 100644 --- a/src/Supportive/Console/Application.php +++ b/src/Supportive/Console/Application.php @@ -62,7 +62,6 @@ protected function getDefaultInputDefinition(): InputDefinition null, InputOption::VALUE_REQUIRED, 'Location where cache file will be stored', - null ), new InputOption( '--config-file', @@ -95,16 +94,15 @@ public function doRun(InputInterface $input, OutputInterface $output): int return parent::doRun($input, $output); } - /** @var string|numeric|null $configFile */ - $configFile = $input->getOption('config-file'); - $config = $input->hasOption('config-file') - ? (string) $configFile - : $currentWorkingDirectory.DIRECTORY_SEPARATOR.'deptrac.yaml'; + /** @var ?string $config */ + $config = $input->getParameterOption(['--config-file', '-c'], null); + $config ??= $currentWorkingDirectory.DIRECTORY_SEPARATOR.'deptrac.yaml'; /** @var ?string $cache */ $cache = $input->getParameterOption('--cache-file', null); $factory = new ServiceContainerBuilder($currentWorkingDirectory); + if (!in_array($input->getArgument('command'), ['init', 'list', 'help', 'completion'], true)) { $factory = $factory->withConfig($config); } @@ -112,11 +110,17 @@ public function doRun(InputInterface $input, OutputInterface $output): int $noCache = $input->hasParameterOption('--no-cache', true); try { - $container = $factory->build($noCache ? false : $cache, $input->hasParameterOption('--clear-cache', true)); + $container = $factory->build( + $noCache ? false : $cache, + $input->hasParameterOption('--clear-cache', true) + ); + $commandLoader = $container->get('console.command_loader'); + if (!$commandLoader instanceof CommandLoaderInterface) { throw new RuntimeException('CommandLoader not initialized. Commands can not be registered.'); } + $this->setCommandLoader($commandLoader); $this->setDefaultCommand('analyse'); } catch (CannotLoadConfiguration $e) {