https://github.com/minicli/minicli
Minimalist, dependency-free framework for building CLI-centric PHP applications
というわけで、試してみた。簡単なサンプルレベルのCLIアプリで、どの程度のことがサポートされてるかをチェックする。
Hello コマンド
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| <?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use Minicli\App; use Minicli\Command\CommandCall;
$app = new App();
$app->setSignature(" Usage: ./minicli [command] [options]
Commands: hello 挨拶する (--name=名前) ");
$app->registerCommand('hello', function (CommandCall $input) use ($app) { $name = $input->getParam('--name') ?? 'World'; $app->getPrinter()->success("Hello, {$name}!"); });
$app->runCommand($argv);
|
helpコマンドとかは、自動で生えることはなくて、setSignature を使って自分で書く必要があります。つまり、本当にミニマルですね。
感想
やはり、The Console Component (Symfony Docs) を使ったほうが良いかも知れない。ミニマルではないけど、helpコマンドとかは自動で出してもらえるほうが助かると思った。
本当にバニラPHPで自作するくらいなら、minicli使ったほうが良いかな…