Implemented contexts, optimizations
This commit is contained in:
27
examples/contexts.php
Normal file
27
examples/contexts.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__."/../vendor/autoload.php";
|
||||
|
||||
use NoccyLabs\Shell\Shell;
|
||||
use NoccyLabs\Shell\Context;
|
||||
|
||||
$shell = new Shell();
|
||||
$shell->addListener("prompt", function ($event, $shell) {
|
||||
$name = $shell->getContextPath();
|
||||
$shell->setPrompt("shell{$name}> ");
|
||||
});
|
||||
|
||||
$root = new Context();
|
||||
$root->addCommand("test", function () {
|
||||
echo "It works!\n";
|
||||
});
|
||||
$root->addCommand("context", function ($name) {
|
||||
$context = new Context($name);
|
||||
$context->name = $name;
|
||||
return $context;
|
||||
});
|
||||
$shell->pushContext($root);
|
||||
|
||||
|
||||
$shell->run();
|
||||
|
Reference in New Issue
Block a user