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
39 changes: 11 additions & 28 deletions bin/phunkie
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@
use Phunkie\Console\Types\ReplSession;
use Phunkie\Effect\IO\IO;
use Phunkie\Effect\IO\IOApp;
use Phunkie\Validation\Validation;
use Phunkie\Effect\IO\IOApp\ParsedOptions;

use function Phunkie\Console\Repl\replLoop;
use function Phunkie\Console\Functions\{setColors, printBanner, loadHistory, saveHistory};
use function Phunkie\Effect\Functions\ioapp\arguments;
use function Phunkie\Effect\Functions\ioapp\option;

use const Phunkie\Effect\Functions\ioapp\NoInput;

(function (){
(function () {
$autoloadPaths = [
__DIR__ . '/../vendor/autoload.php', // Local development (console project)
dirname(__DIR__, 3) . '/autoload.php', // Installed as dependency (vendor/phunkie/console/bin/phunkie -> vendor/autoload.php)
Expand All @@ -38,36 +45,14 @@ use function Phunkie\Console\Functions\{setColors, printBanner, loadHistory, sav
exit(1);
}

class PhunkieConsole extends IOApp {
public function run(?array $args = []): IO
{
// Parse command-line arguments
$colorEnabled = $this->hasColorFlag($args);

// Create initial session
$initialSession = ReplSession::empty();
$pair = setColors($colorEnabled)->run($initialSession);
$session = $pair->_1;

// Load command history from previous sessions
// Print banner and start REPL loop
return loadHistory()
->flatMap(fn() => printBanner($colorEnabled))
->flatMap(fn() => replLoop($session));
}

private function hasColorFlag(?array $args): bool
{
return $args !== null && in_array('-c', $args);
}
}

// Setup signal handlers for graceful exit (Ctrl-C)
if (function_exists('pcntl_signal')) {
// Enable async signals so handlers are called automatically
pcntl_async_signals(true);

pcntl_signal(SIGINT, function() {
pcntl_signal(SIGINT, function () {
// Save history before exiting
saveHistory()->unsafeRun();
echo "\n\nbye \\o\n";
Expand All @@ -76,7 +61,7 @@ use function Phunkie\Console\Functions\{setColors, printBanner, loadHistory, sav
}

// Register shutdown function to save history on normal exit
register_shutdown_function(function() {
register_shutdown_function(function () {
saveHistory()->unsafeRun();
});

Expand All @@ -92,10 +77,8 @@ use function Phunkie\Console\Functions\{setColors, printBanner, loadHistory, sav
}

if ($app === null) {
$app = new PhunkieConsole();
$app = new \Phunkie\Console\PhunkieConsole("1.1.0");
}

$app->run($args)->unsafeRun();
})();


13 changes: 10 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@
"email": "marcello.duarte@gmail.com"
}
],
"repositories": [
{
"type": "vcs",
"url": "https://github.com/phunkie/effect"
}
],
"require": {
"php": "^8.2 || ^8.3 || ^8.4",
"phunkie/phunkie": "^1.0",
"phunkie/effect": "^1.0",
"phunkie/effect": "^1.1",
"nikic/php-parser": "^5.6"
},
"require-dev": {
Expand Down Expand Up @@ -44,7 +50,7 @@
"bin/phunkie"
],
"scripts": {
"test": "vendor/bin/phpunit",
"test": "bin/run-behat-tests.sh",
"cs-fix": "vendor/bin/php-cs-fixer fix --allow-risky=yes",
"cs-check": "vendor/bin/php-cs-fixer fix --dry-run --diff --allow-risky=yes",
"phpstan": "phpstan analyse --memory-limit=512M",
Expand All @@ -57,5 +63,6 @@
"@lint",
"@test"
]
}
},
"prefer-stable": true
}
99 changes: 69 additions & 30 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion features/repl/throw_expressions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Feature: Throw expressions
Given I start the REPL
When I enter "class MyException extends \Exception {}"
And I enter "throw new MyException('Custom error message')"
Then I should see output containing "MyException"
Then I should see output containing "Error"
And I should see output containing "Custom error message"

Scenario: Throw in arrow function with parameter
Expand Down
Loading