Bagi yang pernah tahu Laravel, Symphony, Yii atau framework besar lain yang memiliki fitur interaksi di console (terminal/command line), mungkin pernah bertanya, bisakah kita memiliki fitur tersebut tanpa memakai framework-framework diatas?
Bisa dong. Salah satu library PHP yang bisa kita gunakan untuk membuat aplikasi CLI (command line interface) yaituÂ
Garden-CLI dari om Vanilla
https://github.com/vanilla/garden-cli
Cara Instalasi
Instalasi dengan mudah ke aplikasi existing kita, dengan Composer:
[sourcecode]composer require vanilla/garden-cli[/sourcecode]
Contoh Penggunaan
Contoh penggunaan Garden-CLI antara lain:
[sourcecode]
<?php
// All of the command line classes are in the Garden\Cli namespace.
use Garden\Cli\Cli;
// Require composer's autoloader.
require_once 'vendor/autoload.php';
// Define the cli options.
$cli = new Cli();
$cli->description('Dump some information from your database.')
->opt('host:h', 'Connect to host.', true)
->opt('port:P', 'Port number to use.', false, 'integer')
->opt('user:u', 'User for login if not current user.', true)
->opt('password:p', 'Password to use when connecting to server.')
->opt('database:d', 'The name of the database to dump.', true);
// Parse and return cli args.
$args = $cli->parse($argv, true);
[/sourcecode]
untuk menjalankannya, silakan tambahkan opsi
--help untuk menampilkan keterangan aplikasi.
