Skip to content
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
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
"symfony/console": "^5.0|^6.0|^7.0"
},
"require-dev": {
"laravel/pint": "^1.20.0",
"phpstan/phpstan": "^2.1.2",
"rector/rector": "^2.0.7",
"pestphp/pest": "^3.8",
"pestphp/pest-plugin-type-coverage": "^3.6"
"laravel/pint": "^1.27.1",
"phpstan/phpstan": "^2.1.40",
"rector/rector": "^2.3.8",
"pestphp/pest": "^3.8.5",
"pestphp/pest-plugin-type-coverage": "^3.6.1"
},
"config": {
"allow-plugins": {
Expand Down
1 change: 0 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
privatization: true,
instanceOf: true,
earlyReturn: true,
strictBooleans: true,
)
->withPaths([
__DIR__ . '/src',
Expand Down
19 changes: 18 additions & 1 deletion src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Artemeon\Console;

use Artemeon\Console\Styles\ArtemeonStyle;
use Closure;
use Symfony\Component\Console\Command\Command as SymfonyCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -16,6 +17,8 @@ class Command extends SymfonyCommand
use Concerns\ConfiguresPrompts;
use Concerns\PromptsForMissingInput;

public static ?Closure $postCallClosure = null;

/**
* The name and signature of the console command.
*/
Expand Down Expand Up @@ -87,7 +90,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return self::FAILURE;
}

return $callable();
$exit = $callable();

if (self::$postCallClosure instanceof Closure) {
call_user_func(self::$postCallClosure, $exit);
}

return $exit;
}

protected function configureUsingFluentDefinition(): void
Expand All @@ -111,4 +120,12 @@ public function setHidden(bool $hidden = true): static

return $this;
}

/**
* @param Closure(int): void $closure
*/
public static function setupPostCallClosure(Closure $closure): void
{
self::$postCallClosure = $closure;
}
}
2 changes: 1 addition & 1 deletion src/Concerns/ConfiguresPrompts.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private function promptUntilValid(Closure $prompt, bool | string $required, ?Clo
while (true) {
$result = $prompt();

if ($required && ($result === '' || $result === [] || $result === false)) {
if ($required && in_array($result, ['', [], false], true)) {
$this->output->error(is_string($required) ? $required : 'Required.');

continue;
Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/InteractsWithIO.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ public function info(array | string $message): void

public function line(string $message, ?string $style = null, int | string | null $verbosity = null): void
{
$styled = $style !== null && $style !== '' && $style !== '0' ? sprintf('<%s>%s</%s>', $style, $message, $style) : $message;
$styled = in_array($style, [null, '', '0'], true) ? sprintf('<%s>%s</%s>', $style, $message, $style) : $message;

$this->output->writeln($styled, $this->parseVerbosity($verbosity));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/PromptsForMissingInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected function promptForMissingArguments(InputInterface $input, OutputInterf
/**
* Prompt for missing input arguments using the returned questions.
*
* @return array<string, string>
* @return array<string, string|Closure>
*/
protected function promptForMissingArgumentsUsing(): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected static function name(string $expression): string
throw new InvalidArgumentException('Unable to determine command name from signature.');
}

return $matches[0];
return $matches[0] ?? '';
}

/**
Expand Down