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

Fix --help doesn't work if deptrac.yaml file is missing issue #1088

Merged
merged 1 commit into from
Jan 27, 2023
Merged
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
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