asilgag / cli-wrapper
A simple PHP wrapper over CLI commands
Installs: 4 144
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.1.0
This package is auto-updated.
Last update: 2024-05-08 12:44:55 UTC
README
A simple PHP wrapper over CLI commands.
Installation
composer require asilgag/cli-wrapper
Usage
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
}