Download the PHP package adhocore/cli without Composer
On this page you can find all versions of the php package adhocore/cli. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package cli
adhocore/cli
Framework agnostic Command Line Interface utilities and helpers for PHP. Build Console App with ease, fun and love.
- Command line application made easy
- Inspired by nodejs commander (thanks tj)
- Zero dependency.
- For PHP7, PHP8 and for good
What's included
Core: Shell
IO: Stream reader
Other: Autocompletion
Installation
Usage
Argv parser
Command help
It can be triggered manually with $command->showHelp()
or automatic when -h
or --help
option is passed to $command->parse()
.
For above example, the output would be:
Command version
It can be triggered manually with $command->showVersion()
or automatic when -V
or --version
option is passed to $command->parse()
.
For above example, the output would be:
Console app
Definitely check adhocore/phint - a real world console application made using adhocore/cli
.
Here we simulate a git
app with limited functionality of add
, and checkout
.
You will see how intuitive, fluent and cheese building a console app is!
Git app
Organized app
Instead of inline commands/actions, we define and add our own commands (having interact()
and execute()
) to the app:
Grouping commands
Grouped commands are listed together in commands list. Explicit grouping a command is optional.
By default if a command name has a colon :
then the part before it is taken as a group,
else *
is taken as a group.
Example: command name
app:env
has a default groupapp
, command nameappenv
has group*
.
Exception handler
Set a custom exception handler as callback. The callback receives exception & exit code. The callback may rethrow exception or may exit the program or just log exception and do nothing else.
App help
It can be triggered manually with $app->showHelp()
or automatic when -h
or --help
option is passed to $app->parse()
.
Note If you pass something like ['app', cmd', '-h']
to $app->parse()
it will automatically and instantly show you help of that cmd
and not the $app
.
For above example, the output would be:
App version
Same version number is passed to all attached Commands. So you can trigger version on any of the commands.
Shell
Very thin shell wrapper that provides convenience methods around proc_open()
.
Basic usage
Advanced usage
Timeout
Cli Interaction
You can perform user interaction like printing colored output, reading user input programatically and moving the cursors around with provided Ahc\Cli\IO\Interactor
.
Confirm
Single choice
Multiple choices
Prompt free input
Prompt with validation
Prompt hidden
On windows platform, it may change the fontface which can be fixed.
IO Components
The interactor is composed of Ahc\Cli\Input\Reader
and Ahc\Cli\Output\Writer
while the Writer
itself is composed of Ahc\Cli\Output\Color
. All these components can be used standalone.
Color
Color looks cool!
Simple usage
Custom style
Cursor
Move cursor around, erase line up or down, clear screen.
Progress Bar
Easily add a progress bar to your output:
You can also manually advance the bar:
You can override the progress bar options to customize it to your liking:
Writer
Write anything in style.
Output formatting
You can call methods composed of any combinations:
'<colorName>', 'bold', 'bg', 'fg', 'warn', 'info', 'error', 'ok', 'comment'
... in any order (eg: bgRedFgBlaock
, boldRed
, greenBold
, commentBgPurple
and so on ...)
Free style
Many colors with one single call: wrap text with tags <method>
and </end>
For NL/EOL just use <eol>
or </eol>
or <eol/>
.
Great for writing long colorful texts for example command usage info.
Raw output
Tables
Just pass array of assoc arrays. The keys of first array will be taken as heading. Heading is auto inflected to human readable capitalized words (ucwords).
Gives something like:
Designing table look and feel
Just pass 2nd param $styles
:
Justify content (Display setting)
If you want to display certain configurations (from your .env file for example) a bit like Laravel does (via the php artisan about
command) you can use the justify
method.
Gives something like:
You can use the sep
parameter to define the separator to use.
Gives something like:
In addition, the text color, the background color and the thickness of the two texts can be defined via the 3rd argument of this method.
For more details regarding the different color options, see Custom style
Reader
Read and pre process user input.
Exceptions
Whenever an exception is caught by Application::handle()
, it will show a beautiful stack trace and exit with non 0 status code.
Autocompletion
Any console applications that are built on top of adhocore/cli can entertain autocomplete of commands and options in zsh shell with oh-my-zsh.
All you have to do is add one line to the end of ~/.oh-my-zsh/custom/plugins/ahccli/ahccli.plugin.zsh
:
compdef _ahccli <appname>
Example: compdef _ahccli phint
for phint.
That is cumbersome to perform manually, here's a complete command you can copy/paste/run:
One time setup
Load ahccli plugin
This is also one time setup.
Registering app
Of course you can add multiple apps, just change appname in above command
Then either restart the shell or source the plugin like so:
Trigger autocomplete
Related
- adhocore/phalcon-ext · Phalcon extension using
adhocore/cli
- adhocore/phint · PHP project scaffolding app using
adhocore/cli
- adhocore/type-hinter · Auto PHP7 typehinter tool using
adhocore/cli
Contributors
License
© 2017-2020, Jitendra Adhikari | MIT
Credits
This project is release managed by please.