Download the PHP package toolkit/pflag without Composer
On this page you can find all versions of the php package toolkit/pflag. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download toolkit/pflag
More information about toolkit/pflag
Files in toolkit/pflag
Package pflag
Short Description Command line flag parse library of the php
License MIT
Homepage https://github.com/php-toolkit/pflag
Informations about the package pflag
PHP Flag
Generic PHP command line flags parse library
Github: php-toolkit/pflag
Features
- Generic command line options and arguments parser.
- Support set value data type(
int,string,bool,array
), will auto format input value. - Support set multi alias names for an option.
- Support set multi short names for an option.
- Support set default value for option/argument.
- Support read flag value from ENV var.
- Support set option/argument is required.
- Support set validator for check input value.
- Support auto render beautiful help message.
Flag Options:
- Options start with
-
or--
, and the first character must be a letter - Support long option. eg:
--long
--long value
- Support short option. eg:
-s -a value
- Support define array option
- eg:
--tag php --tag go
will gettag: [php, go]
- eg:
Flag Arguments:
- Support binding named arguemnt
- Support define array argument
Quick build command
- Use
Toolkit\PFlag\CliCmd
to quickly build a simple command application - Use
Toolkit\PFlag\CliApp
to quickly build a command application that supports subcommands
Install
- Require PHP 8.0+
composer
Flags Usage
Flags - is an cli flags(options&argument) parser and manager.
example codes please see example/flags-demo.php
Create Flags
Define options
Examples for add flag option define:
Define Arguments
Examples for add flag argument define:
Parse Input
Show help
Output:
Run demo:
Output:
Get Value
Get flag value is very simple, use method getOpt(string $name)
getArg($nameOrIndex)
.
TIP: Will auto format input value by define type.
Options
Arguments
Build simple cli app
In the pflag, built in CliApp
and CliCmd
for quick create and run an simple console application.
Create simple alone command
Build and run a simple command handler. see example file example/clicmd.php
Usage:
- Display help:
- Run command:
Create an multi commands app
Create an multi commands application, run subcommand. see example file example/cliapp.php
Usage:
- Display commands:
- Command help:
- Run command:
Flag rule
The options/arguments rules. Use rule can quick define an option or argument.
- string value is rule(
type;desc;required;default;shorts
). - array is define item
SFlags::DEFINE_ITEM
- supported type see
FlagType::*
For options
- option allow set shorts
TIP: name
long,a,b
-long
is the option name. remaininga,b
is short names.
For arguments
- argument no alias/shorts
- array value only allow defined at last
Definition item
The const Flags::DEFINE_ITEM
:
Custom settings
Settings for parse
Setting for render help
support some settings for render help
- custom help message renderer
Unit tests
test with coverage:
Project use
Check out these projects, which use https://github.com/php-toolkit/pflag :
- inhere/console Full-featured php command line application library.
- kite Kite is a tool for help development.
- More, please see Packagist
License
MIT
All versions of pflag with dependencies
ext-mbstring Version *
toolkit/cli-utils Version ~2.0
toolkit/stdlib Version ~2.0