Skip to content

quick start

Inhere edited this page Jan 10, 2019 · 4 revisions

快速开始

如下,新建一个入口文件。 就可以开始使用了

// file: examples/app
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;

$meta = [
    'name' => 'My Console App',
    'version' => '1.0.2',
];
$input = new Input;
$output = new Output;
// 通常无需传入 $input $output ,会自动创建
$app = new \Inhere\Console\Application($meta, $input, $output);

// add command routes
$app->command('demo', function (Input $in, Output $out) {
    $cmd = $in->getCommand();

    $out->info('hello, this is a test command: ' . $cmd);
});
// ... ...

// run
$app->run();

然后在命令行里执行 php examples/app, 立即就可以看到如下输出了:

'app-command-list'

Alone Commands 中的 demo 就是我们上面添加的命令