Download the PHP package corneltek/getoptionkit without Composer
On this page you can find all versions of the php package corneltek/getoptionkit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download corneltek/getoptionkit
More information about corneltek/getoptionkit
Files in corneltek/getoptionkit
Package getoptionkit
Short Description Powerful command-line option toolkit
License MIT
Homepage http://github.com/c9s/GetOptionKit
Informations about the package getoptionkit
GetOptionKit
Code Quality
Versions & Stats
A powerful option parser toolkit for PHP, supporting type constraints, flag, multiple flag, multiple values and required value checking.
GetOptionKit supports PHP5.3, with fine unit testing with PHPUnit testing framework.
GetOptionKit is object-oriented, it's flexible and extendable.
Powering PHPBrew https://github.com/phpbrew/phpbrew, CLIFramework https://github.com/c9s/CLIFramework and AssetKit https://github.com/c9s/AssetKit
Features
- Simple format.
- Type constrant.
- Multiple value, requried value, optional value checking.
- Auto-generated help text from defined options.
- Support app/subcommand option parsing.
- Option Value Validator
- Option Suggestions
- SPL library.
- HHVM support.
Requirements
- PHP 5.3+
Install From Composer
Supported Option Formats
simple flags:
with multiple values:
specify value with equal sign:
with normal arguments:
Option SPEC
v|verbose flag option (with boolean value true)
d|dir: option require a value (MUST require)
d|dir+ option with multiple values.
d|dir? option with optional value
dir:=string option with type constraint of string
dir:=number option with type constraint of number
dir:=file option with type constraint of file
dir:=date option with type constraint of date
dir:=boolean option with type constraint of boolean
d single character only option
dir long option name
Command Line Forms
app [app-opts] [app arguments]
app [app-opts] subcommand [subcommand-opts] [subcommand-args]
app [app-opts] subcmd1 [subcmd-opts1] subcmd2 [subcmd-opts] subcmd3 [subcmd-opts3] [subcommand arguments....]
Documentation
See more details in the documentation
Demo
Please check examples/demo.php
.
Run:
Print:
* Available options:
-f, --foo <value> option requires a value.
-b, --bar <value>+ option with multiple value.
-z, --zoo [<value>] option with optional value.
-v, --verbose verbose message.
-d, --debug debug message.
--long long option name only.
-s short option name only.
Enabled options:
* key:foo spec:-f, --foo <value> desc:option requires a value.
value => test
* key:bar spec:-b, --bar <value>+ desc:option with multiple value.
Array
(
[0] => 123
[1] => 333
)
Synopsis
Documentation
See https://github.com/c9s/GetOptionKit/wiki for more details.
Option Value Type
The option value type help you validate the input, the following list is the current supported types:
string
number
boolean
file
date
url
email
ip
ipv4
ipv6
regex
And here is the related sample code:
Please note that currently only
string
,number
,boolean
types can be validated.
ContinuousOptionParser
OptionPrinter
GetOptionKit\OptionPrinter can print options for you:
* Available options:
-f, --foo option requires a value.
-b, --bar option with multiple value.
-z, --zoo option with optional value.
-v, --verbose verbose message.
-d, --debug debug message.
--long long option name only.
-s short option name only.
Command-line app with subcommands
For application with subcommands is designed by following form:
[app name] [app opts]
[subcommand1] [subcommand-opts]
[subcommand2] [subcommand-opts]
[subcommand3] [subcommand-opts]
[arguments]
You can check the tests/GetOptionKit/ContinuousOptionParserTest.php
unit test file:
Todo
- Option Spec group.
- option valid value checking.
- custom command mapping.
Command Line Utility Design Concept
- main program name should be easy to type, easy to remember.
- subcommand should be easy to type, easy to remember. length should be shorter than 7 characters.
- options should always have long descriptive name
- a program should be easy to check usage.
General command interface
To list usage of all subcommands or the program itself:
$ prog help
To list the subcommand usage
$ prog help subcommand subcommand2 subcommand3
Hacking
Fork this repository and clone it:
$ git clone git://github.com/c9s/GetOptionKit.git
$ cd GetOptionKit
$ composer install
Run PHPUnit to test:
$ phpunit
License
This project is released under MIT License.