Skip to content

Latest commit

 

History

History
39 lines (33 loc) · 977 Bytes

Command.md

File metadata and controls

39 lines (33 loc) · 977 Bytes

Command

You can register console commands using $command->register()

use CatPaw\Core\CommandBuilder;
use CatPaw\Core\CommandContext;
use CatPaw\Core\Interfaces\CommandRegisterInterface;
use CatPaw\Core\Interfaces\CommandInterface;
use CatPaw\Core\None;
use function CatPaw\Core\ok;

$runner = new class implements CommandInterface {
    /**
     * Build the command.
     * @param  CommandBuilder $builder
     * @return void
     */
    public function build(CommandBuilder $builder):void {
        $builder->required('o','option');
    }

    /**
     * Run the command.
     * @return Result<None>
     */
    public function run(CommandContext $context):Result {
        $value = $context->get('option');
        echo "$value\n";
        return ok();
    }
}

function main(CommandRegisterInterface $command){
    return $command->register($runner);
}

Your command will the execute whenever the console user issues the required parameters of your command.