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

Pass console argument at startup #21

Merged
merged 2 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 1.0.2 under development

- no changes in this release.
- Chg: #21: Add passing input aggregate to the console application (@xepozz)

## 1.0.1 June 17, 2022

Expand Down
10 changes: 7 additions & 3 deletions src/ConsoleApplicationRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Symfony\Component\Console\Input\ArgvInput;
use Throwable;
use Yiisoft\Definitions\Exception\CircularReferenceException;
use Yiisoft\Definitions\Exception\InvalidConfigException;
Expand Down Expand Up @@ -53,11 +54,14 @@ public function run(): void
$application = $container->get(Application::class);
$exitCode = ExitCode::UNSPECIFIED_ERROR;

$input = new ArgvInput();
$output = new ConsoleBufferedOutput();

try {
$application->start();
$exitCode = $application->run(null, new ConsoleBufferedOutput());
$application->start($input);
$exitCode = $application->run($input, $output);
} catch (Throwable $throwable) {
$application->renderThrowable($throwable, new ConsoleBufferedOutput());
$application->renderThrowable($throwable, $output);
} finally {
$application->shutdown($exitCode);
exit($exitCode);
Expand Down