Skip to content

Commit

Permalink
always parse config-file ourselfs
Browse files Browse the repository at this point in the history
  • Loading branch information
gennadigennadigennadi committed Jul 24, 2024
1 parent 02dd89e commit 13b3e19
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Supportive/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ protected function getDefaultInputDefinition(): InputDefinition
null,
InputOption::VALUE_REQUIRED,
'Location where cache file will be stored',
null
),
new InputOption(
'--config-file',
Expand Down Expand Up @@ -95,28 +94,33 @@ 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);
}

$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) {
Expand Down

0 comments on commit 13b3e19

Please sign in to comment.