Download the PHP package brzuchal/command-line without Composer
On this page you can find all versions of the php package brzuchal/command-line. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download brzuchal/command-line
More information about brzuchal/command-line
Files in brzuchal/command-line
Package command-line
Short Description Simple PHP CommandLine argument and option parser
License MIT
Informations about the package command-line
PHP CommandLine argument and option parser
Purpose of this project is to provide modern and complete API for command line argument and option parsing in CLI.
CommandLine generics
When you type ENV=prod php -d "error_reporting=E_ALL" script.php test --debug
only last command line components are visible
in script.php
scope at runtime.
Following analysis such command line consists of:
Runtime command line generic components are: command
+ arguments
+ options
.
Examples
The simplest way to retrieve parameters from CLI with definitions:
The simplest way to retrieve parameters from CLI without definition:
Which for php test.php command --env=prod --debug -f -c
gives:
There is also a way to retrieve parameters with it's definitions and their requirements:
Which also validates if options have values and are required.
Parsing command php test.php command --env=prod --debug -f -c
gives:
TODO
- [x] Parse options from array
- [ ] Parse options from string
- [ ] Validates required values
- [ ] Provide default values
- [x] Parse arguments from array
- [ ] Parse arguments from string
- [ ] Validates existence of arguments
License
The MIT License (MIT)
Copyright (c) 2017 Michał Brzuchalski [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFc MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.