Download the PHP package programster/command without Composer
On this page you can find all versions of the php package programster/command. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download programster/command
More information about programster/command
Files in programster/command
Package command
Short Description A library for making CLI commands.
License MIT
Homepage http://blog.programster.org/
Informations about the package command
CLI Command PHP Package
A package to simplify the creation of CLI commands in PHP, with BASH autocompletion support.
Execute Parameters
When writing your execute
function, be aware that the keys for the options and switches will
always be the longhand name, and without any hyphens. E.g. shell
instead of s
when the user
enters --shell
or -s
.
Option Value Validation
We don't validate any of the values that get passed into the options, so you will need to perform any validation yourself.
Example
Below is an example, in which I have written a command that wraps around docker-exec, to allow
me to tab-complete the container names, and then enter them by ID, defaulting to the BASH shell,
but allowing the user to provide the --shell
or -s
option to specify they want to use sh
instead.
Install Command
Once you have built a command using this framework, you will want to know how to "install" it, so that you can execute it from anywhere, and the BASH autocomplete functionality works.
Put It In Your $PATH
Place the command, or a symlink to it, in your $PATH at /usr/bin/{command name}. Make sure the executable flag is set.
Creating The BASH Completion File
Unfortunately, one still needs to create a completion file for your program, in order to tell
BASH to ask your program for the tab hints. One case easily create this using your program, using
the "hidden" --generate-autocomplete-file
switch like so:
Alternatively, you can manually create your own completion script. Below is an example for a custom
command you created called my-command
.
Now open a new BASH shell, and you should see it working!.
Roadmap
- Prevent suggesting options/switches that have already been passed.