// 检查是否在命令行环境下运行
if (php_sapi_name() !== 'cli') {
die('This script can only be run from the command line.' 、PHP_EOL);
}
// 函数:显示帮助信息
function showHelp()
{
echo Usage: php cli-tool.php [command] [options] 、PHP_EOL;
echo PHP_EOL;
echo Commands: 、PHP_EOL;
echo hello [name] Say hello to someone 、PHP_EOL;
echo version Show version 、PHP_EOL;
echo help Show this help message 、PHP_EOL;
echo PHP_EOL;
}
// 函数:处理命令
function handleCommand($argv)
{
$command = $argv[1] ?? 'help';
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class HelloCommand extends Command
{
protected static $defaultName = 'app:hello';
protected function configure()
{
$this
-setDescription('Say hello to someone')
-addArgument('name', InputArgument::REQUIRED, 'Who do you want to greet?');
}