-
Notifications
You must be signed in to change notification settings - Fork 51
Getting Started
Kyle edited this page Jun 5, 2019
·
10 revisions
Add cliframework to your composer.json:
{
"require": {
"corneltek/cliframework": "~3.0"
}
}
Or, you can run the command below to install the dependencies:
composer require "corneltek/cliframework:~3.0"
To use CLIFramework, please define the application class first,
src/YourApp/Console.php
:
namespace YourApp;
use CLIFramework\Application;
class Console extends Application
{
/* init your application options here */
public function options($opts)
{
$opts->add('v|verbose', 'verbose message');
$opts->add('path:', 'required option with a value.');
$opts->add('path?', 'optional option with a value');
$opts->add('path+', 'multiple value option.');
}
/* register your command here */
public function init()
{
parent::init();
$this->command( 'list', '\YourApp\Command\ListCommand' );
$this->command( 'foo', '\YourApp\Command\FooCommand' );
$this->command( 'bar' ); // initialize with \YourApp\Command\BarCommand
}
}
Then define your command class:
src/YourApp/Command/ListCommand.php
:
namespace YourApp\Command;
use CLIFramework\Command;
class ListCommand extends Command {
public function brief()
{
return 'awesome help brief.';
}
function init()
{
// register your subcommand here ..
}
function options($opts)
{
// command options
}
function execute($arg1,$arg2,$arg3 = 0)
{
$logger = $this->logger;
$logger->info('execute');
$logger->error('error');
$input = $this->ask('Please type something');
}
}
To start your application, create a new script file named bin/yourapp
:
require 'vendor/autoload.php';
$app = new \YourApp\Console;
$app->runWithTry($argv);
To test your application:
php bin/yourapp