Download the PHP package joetjen/abstractcli without Composer
On this page you can find all versions of the php package joetjen/abstractcli. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download joetjen/abstractcli
More information about joetjen/abstractcli
Files in joetjen/abstractcli
Package abstractcli
Short Description Abstract base class for command line parsing
License MIT
Homepage http://github.com/joetjen/php-abstractcli
Informations about the package abstractcli
AbstractCLI
A small, dependency-free abstract base class for building command line PHP scripts: define your
options and arguments declaratively, and AbstractCLI takes care of parsing $argv, validating
input, and printing --help/--version output for you.
It ships with three built-in options out of the box:
-h,--help- print usage and exit-v,--verbose- a boolean switch, off by default-V,--version- print the program name/version and exit
Documentation
This README covers requirements, installation and a complete quick-start example. For everything else:
- QUICKSTART.md - the fastest path to a working script.
- TUTORIAL.md - a guided, step-by-step walkthrough that builds up a realistic command feature by feature, verifying its output at every step.
- CHEATSHEET.md - a condensed reference for the full API, plus a table of behaviors that are easy to get wrong.
- EXAMPLES.md - short, standalone, copy-pasteable scripts for common cases.
- CHANGELOG.md - notable changes, release by release.
- CONTRIBUTION.md - how to set up a dev environment, run the tests, and what a good pull request looks like.
- LICENSE - MIT.
Requirements
- PHP 7.4 or 8.0+ (tested against PHP 8.4)
Installation
Quick start
For a step-by-step explanation of how this example was built up, see TUTORIAL.md.
API at a glance
addOption(array $params)/addArgument(array $params)- declare options/arguments in your constructor. Both return$thisand throwCLIExceptionimmediately if the definition is invalid.AbstractCLI::run(array $args)- the static entry point; instantiates your class, parses$args(pass$argv), and callsexecute(). Any error - and even--help/--version- ends the process viaexit()from insiderun(), so only the success path returns normally.- Inside
execute():getOption($name, $default = null),getArgument($idx, $default = null)andis($name)read back what was parsed. setVersion(),setSummary(),setFooter()customize--help/--versionoutput.
The full reference, including the exact rules for option types and a few genuinely surprising
edge cases (an "..." argument that doesn't collect an array; a TYPE__MANDATORY option that
isn't actually required to be present), is in
CHEATSHEET.md.
Development
The test suite (tests/) covers option/argument configuration and validation, the parser
(including the edge cases mentioned above), help/usage/version output formatting, and full
end-to-end run() behavior (exit codes included) via real child PHP processes. See
CONTRIBUTION.md for
more.
License
Released under the MIT License.