Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

explizit arguments get #62

Open
wants to merge 1 commit into
base: 2.0.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading