codecounter/php-argv

用于在命令行中处理 PHP argv 的库。

dev-master 2015-01-29 06:51 UTC

This package is auto-updated.

Last update: 2024-09-07 21:43:28 UTC


README

用于在命令行中处理 PHP argv 的库。

安装

使用 composer

{
    ...
    "require": {
        "codecounter/php-argv": "0.1.0"
    }
}

不使用 composer

require '/path/to/php-argv/autoload.php';

使用方法

// first, create a php-argv instance
$phpArgv = new \CodeCounter\PHPArgv\Argv();

// set version, desc
$phpArgv->version('1.0.0')
    ->desc('Some description for this command');

// create default module(sub command)
$phpArgv->module()
    // set description for this module
    ->desc()
    // set allowed options
    ->options(array(
        array(
            'key' => 'num',
            'type' => 'int'
        ),
        array(
            'key' => 'path',
            'type '=> 'path'
        )
    ))
    ->onProcess(function ($module, $options) {
        if (empty($options) || isset($options['help'])) {
            $module->defaultHelp();
        }

        // other logic
    });

// create another module
$phpArgv->module('another-module')
    ...

// parse argv, default is global argv
$phpArgv->parse();

文档

[稍后补充]

测试

cd /path/to/php-argv/tests
php index.php --help