asilgag/cli-wrapper

CLI命令的简单PHP包装器

v1.0.1 2024-03-08 09:29 UTC

This package is auto-updated.

Last update: 2024-09-08 13:27:51 UTC


README

CLI命令的简单PHP包装器。

安装

composer require asilgag/cli-wrapper

用法

use Asilgag\CliWrapper\CliWrapper;
use Asilgag\CliWrapper\CliCommand;

// Create a new CLI Wrapper
$cli = new CliWrapper();

// Set environment variables if needed.
$cli->setEnvironment('FOO', 'baz');

// Set global options for specific commands.
// In this example, all "rsync" commands will be suffixed with "--quiet".
$cli->getGlobalOptions('rsync')->add('--quiet');

// Create new command.
$command = new CliCommand('rsync', ['-avzh', '/source/path', '/target/path/']);

// Execute command. It will throw a RuntimeException if it exits with a non-zero code.
try {
    $cli->exec($command);
}
catch (RuntimeException $e) {
    // Do some logging
}