Download the PHP package asika/simple-console without Composer
On this page you can find all versions of the php package asika/simple-console. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download asika/simple-console
More information about asika/simple-console
Files in asika/simple-console
Package simple-console
Short Description One file console framework to help you write build scripts.
License MIT
Informations about the package simple-console
PHP Simple Console
Single file console framework to help you write build scripts.
Installation
Use composer:
Or downlaod single file to use: Download Here
Getting Started
Use closure
Or Create your own class.
Show HELP
Add -h
or --help
to show usage, you can add custom usage to $this->help
, or override $this->getHelp()
.
If you want to change h
and help
option, override $this->helpOptions = array('...')
.
Handle Error
Just throw Exception in doExecute()
, Console will auto catch error.
Add -v
to show backtrace if error.
Handle Wrong Arguments
Wrong Argument use \Asika\SimpleConsole\CommandArgsException
Console will auto show help information.
Multiple Commands
Use delegate()
to delegate to different methods.
Now you can add sub commands
If you want to strip first argument after delgated, you can follow this code:
Now can use getArgument(0)
in sub method and ignore the first command name.
The is another way:
API
getArgument($order[, $default = null])
setArgument($order, $$value)
getOption($name: array|string[, $default = null])
Get option --foo
Get option -f
or --foo
, first match will return.
NOTE:
-abc
will convert toa => 1, b => 1, c => 1
And-vvv
will convert tov => 3
setOption($name, $value)
Set otpion to toption list. $name
also support array.
out($string[, $newline: bool = false])
Write to STDOUT,
err($string[, $newline: bool = false])
Write to STDERR
in($string[$default = null, $bool = false)
Ask a question, read from STDIN
Read as boolean, add true to third argument:
yes, y, 1, true
will convert toTRUE
no, n, 0, false
will convert toFALSE
exec($cmd)
A proxy to execute a cmd by exec()
and return value.
It will add a title >> {your command}
before exec so you will know what has been executed.