jet/console

构建命令行应用的简单包

v0.1 2012-08-02 09:45 UTC

This package is not auto-updated.

Last update: 2024-09-28 12:00:36 UTC


README

Travis status

Jet Console

Jet Console 包帮助您为应用程序创建简单、可靠且可测试的命令行工具。您可以轻松创建用于任务、部署等的命令行元素。

为什么?

我创建了这个简单的控制台包来简化命令行应用程序的创建。它不像 Symfony Console 组件那样复杂,它更简单、更快、更灵活。

安装

只需下载 Git 仓库并获取自动加载。或者手动加载文件。但我强烈推荐获取自动加载文件(真的,手动加载所有文件真是太疯狂了)。

如何使用

要使用此控制台包,您只需创建自己的命令

<?php

namespace Your\Namespace;

use Jet\Console\Command\AbstractCommand;

class ExampleCommand extends AbstractCommand
{
    public function init()
    {
        $this
            ->setName('example')
            ->setDescription('An example command')
            ->addArgument('hello', Argument::OPTIONAL, null, 'description');
    }

    public function execute()
    {
        if ($this->hasArgument('hello')) {
            return $this->someMethod();
        }

        $this->display('No argument found');
    }

    public function someMethod()
    {
        $argument = $this->getArgument('hello');
        $this->display("hello {$argument}");
    }
}

现在,要使用您的命令,您需要创建运行它的文件(在 bin 目录中)!(如果您是 Windows 用户,请删除第一行)

#!/usr/bin/env php
<?php

//include your autoloader
include_once __DIR__ . '/../../autoload.dist.php';

Use Jet\Console\Console;
Use Your\Namespace;

$console = new Console('name', 'version');
$console->addCommand(new ExampleCommand);
$console->run();

让我们运行!

bin/test example --hello you

测试

只需运行 phpunit 或查看 travis 状态

请随时贡献!

  • 分支
  • 报告错误
  • 帮助开发
  • 给我买一台新 Mac(什么?)

许可

BSD 许可证 下发布