Download the PHP package jacekciach/commandline without Composer
On this page you can find all versions of the php package jacekciach/commandline. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jacekciach/commandline
More information about jacekciach/commandline
Files in jacekciach/commandline
Package commandline
Short Description A simple command-line options parser
License MIT
Informations about the package commandline
CommandLine
A simple command-line options parser.
The main idea was to create a class that will not require any configuration.
A basic usage is to just create a new object and go.
Description
The class parses all arguments passed in $argv
. Parsed arguments are easily accessed with class' methods. These methods are documents in CommandLine.php
.
A command-line argument can be either an option
or a param
:
options
have to be passed beforeparams
; when the parser encounters the firstparam
, all arguments that come after will be treated asparams
as well- an
option
is an argument starting with a dash-
(i.e.-v
,-4=yes
) or dashes--
(i.e.--enabled
,--start=now
) params
start with a first argument not being anoption
- the class generally won't filter
options
, make them required, optional, etc. -
however, the class supports
$allowedOptions
and$shortOptionsMap
(see the class'__construct
documentation); they are optional andCommandLine
works perfectly well without using themA developer needs to implement a logic connected with parsed arguments (their meaning, correctness, dependencies, etc.). The class will not take care of these things: its purpose is to be a convenient "reader" of
$argv
.
Installation
Requirements
- PHP 7
with Composer
without Composer
Just download CommandLine.php
from the repository; this is the only required file.
Then include this file in your code with include
or require
.
Examples
Example 1.
So a command:
will return something like:
Example 2.
will output: