Skip to content

Commit

Permalink
Merge pull request #1088 from maciejkosiarski/1074-deptrac-help-fix
Browse files Browse the repository at this point in the history
Fix --help doesn't work if deptrac.yaml file is missing issue
  • Loading branch information
Denis Brumann authored Jan 27, 2023
2 parents 9ddafe0 + c2a7654 commit c37fd27
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/Supportive/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Qossmic\Deptrac\Supportive\Console;

use Qossmic\Deptrac\Supportive\DependencyInjection\Exception\CannotLoadConfiguration;
use Qossmic\Deptrac\Supportive\DependencyInjection\ServiceContainerBuilder;
use RuntimeException;
use Symfony\Component\Console\Application as BaseApplication;
Expand Down Expand Up @@ -107,14 +108,21 @@ public function doRun(InputInterface $input, OutputInterface $output): int
$factory = $factory->withCache($cache);
}

$container = $factory->build();

$commandLoader = $container->get('console.command_loader');
if (!$commandLoader instanceof CommandLoaderInterface) {
throw new RuntimeException('CommandLoader not initialized. Commands can not be registered.');
try {
$container = $factory->build();
$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) {
if (false === $input->hasParameterOption(['--help', '-h'], true)) {
throw $e;
}

$this->setDefaultCommand('help');
}
$this->setCommandLoader($commandLoader);
$this->setDefaultCommand('analyse');

return parent::doRun($input, $output);
}
Expand Down

0 comments on commit c37fd27

Please sign in to comment.