react-shell/examples/commands.php

24 lines
661 B
PHP
Raw Permalink Normal View History

2024-02-27 01:22:49 +00:00
<?php
use NoccyLabs\React\Shell\CommandHandler;
use React\EventLoop\Loop;
require_once __DIR__."/../vendor/autoload.php";
$shell = new NoccyLabs\React\Shell\Shell();
$commands = new CommandHandler();
$commands->add('help', function ($args, $shell) {
$shell->write("This could be usage help :)\n");
2024-02-27 14:03:40 +00:00
$shell->write("Exit by pressing ^C\n");
2024-02-27 01:22:49 +00:00
});
2024-02-27 14:03:40 +00:00
$commands->on('command', function ($command, $args, $shell) {
$shell->write("Bad command '{$command}', try help.\n");
$shell->write("Arguments passed: ".json_encode($args)."\n");
2024-02-27 01:22:49 +00:00
});
$shell->on('prompt', function ($shell) {
$shell->setPrompt(date(">> "));
});
$shell->on('input', $commands);