Download the PHP package siktec/just-cli without Composer
On this page you can find all versions of the php package siktec/just-cli. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download siktec/just-cli
More information about siktec/just-cli
Files in siktec/just-cli
Informations about the package just-cli
Just CLI
[!NOTE] Just CLI is a fork of adhocore/php-cli which is an amazing CLI framework. This fork is for adding some features that may not be suitable for the original project. Some of the features are:
- [x] Negative numbers in arguments.
- [x] Support for multiple variadic arguments with a grouping option (e.g.
$ app cmd [arg11 arg12] --opt [val1 val2]
)- [ ] Add support for a
structured
CLI app that will auto register commands, views, layouts, etc.- [ ] Add support for Themes.
Framework agnostic Command Line Interface utilities and helpers for PHP. Build Console App with ease, fun and love.
- Zero dependency.
- For PHP 8.0+ only.
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
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 JCli\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 JCli\Input\Reader
and JCli\Output\Writer
while the Writer
itself is composed of JCli\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: bgRedFgBlack
, 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
:
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 siktec/just-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/jcli.plugin.zsh
:
compdef _jcli <appname>
Example: compdef _jcli your-cli-app
for your cli app named your-cli-app
That is cumbersome to perform manually, here's a complete command you can copy/paste/run:
One time setup
Load JCli 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: