Skip to content

Commit 1e754a8

Browse files
committed
refactor(app): add onExit prop, execute or action can return exit code
1 parent 2319370 commit 1e754a8

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/Application.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Application
3939
protected $name;
4040

4141
/** @var string App version */
42-
protected $version = '0.0.1';
42+
protected $version = '';
4343

4444
/** @var string Ascii art logo */
4545
protected $logo = '';
@@ -49,7 +49,10 @@ class Application
4949
/** @var Interactor */
5050
protected $io;
5151

52-
public function __construct(string $name, string $version = '', callable $onExit = null)
52+
/** @var callable The callable to perform exit */
53+
protected $onExit;
54+
55+
public function __construct(string $name, string $version = '0.0.1', callable $onExit = null)
5356
{
5457
$this->name = $name;
5558
$this->version = $version;
@@ -267,9 +270,9 @@ public function handle(array $argv)
267270
$exitCode = 255;
268271

269272
try {
270-
$command = $this->parse($argv);
271-
$this->doAction($command);
272-
$exitCode = 0;
273+
$command = $this->parse($argv);
274+
$result = $this->doAction($command);
275+
$exitCode = \is_int($result) ? $result : 0;
273276
} catch (\Throwable $e) {
274277
$this->outputHelper()->printTrace($e);
275278
}

0 commit comments

Comments
 (0)