Tasker/bin/tasker

46 lines
1 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env php
<?php
declare(strict_types=1);
require_once __DIR__ . '/../vendor/autoload.php';
use Phred\Tasker\Runner;
use Phred\Tasker\ArgvParser;
use Phred\TaskerBridges\Phred\InputAdapter;
use Phred\TaskerBridges\Phred\OutputAdapter;
$runner = new Runner();
// $runner->discover();
$parser = new ArgvParser($argv);
$commandName = $parser->getCommandName() ?: 'list';
$command = $runner->find($commandName);
$output = new OutputAdapter(!$parser->isNoAnsi());
$output->setVerbosity($parser->getVerbosity());
if (!$command) {
$output->error(sprintf('Command "%s" not found.', $commandName));
exit(1);
}
// Map remaining arguments to command arguments
$cmdArgs = $command->getArguments();
$remaining = $parser->getRemainingArguments();
$mappedArgs = [];
$i = 0;
foreach ($cmdArgs as $name => $desc) {
if (isset($remaining[$i])) {
$mappedArgs[$name] = $remaining[$i];
}
$i++;
}
$input = new InputAdapter($mappedArgs, []);
$exitCode = $runner->run($command, $input, $output);
exit($exitCode);