PHPackages                             net\_bazzline/php\_component\_cli\_arguments - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. net\_bazzline/php\_component\_cli\_arguments

ActiveLibrary[CLI &amp; Console](/categories/cli)

net\_bazzline/php\_component\_cli\_arguments
============================================

free as in freedom php cli command thin wrapper to easy up usage and validation of command line arguments

2.1.0(3y ago)32.3k4LGPL-3.0-onlyPHPPHP ~8.0

Since Apr 23Pushed 3y ago4 watchersCompare

[ Source](https://github.com/bazzline/php_component_cli_arguments)[ Packagist](https://packagist.org/packages/net_bazzline/php_component_cli_arguments)[ RSS](/packages/net-bazzline-php-component-cli-arguments/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (1)Versions (14)Used By (4)

Argument Handling for PHP CLI Scripts
=====================================

[](#argument-handling-for-php-cli-scripts)

This project aims to deliver a easy to use and free as in freedom php command component.

The build status of the current master branch is tracked by Travis CI: [![Build Status](https://camo.githubusercontent.com/c25900dc0d1c0a3f375c4974edaab149673497bf62d8b0c6409326c7ac574c8a/68747470733a2f2f7472617669732d63692e6f72672f62617a7a6c696e652f7068705f636f6d706f6e656e745f636c695f617267756d656e74732e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/bazzline/php_component_cli_arguments)[![Latest stable](https://camo.githubusercontent.com/5710c1939024bf8f4828d3614bb8bb69f0a0f0c18fea77f4c6e01075fa0d8877/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e65745f62617a7a6c696e652f7068705f636f6d706f6e656e745f636c695f617267756d656e74732e737667)](https://packagist.org/packages/net_bazzline/php_component_cli_arguments)

The scrutinizer status are: [![code quality](https://camo.githubusercontent.com/f3749eea26696dcd4b71ff05db482a2a215b0b89c2a48dca06d753d63f1745b0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f62617a7a6c696e652f7068705f636f6d706f6e656e745f636c695f617267756d656e74732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/bazzline/php_component_cli_arguments/) | [![build status](https://camo.githubusercontent.com/bd6fcfa0968b14c65ebb55eb2873449e46928352955c4f763d115725b71a0733/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f62617a7a6c696e652f7068705f636f6d706f6e656e745f636c695f617267756d656e74732f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/bazzline/php_component_cli_arguments/)

The versioneye status is: [![Dependency Status](https://camo.githubusercontent.com/6128c6e38bd3892cd459cd0624f4e4a19e42f4416a9f43675f794f29ecdfeff0/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3535333934313536306232343232356566363030303030322f62616467652e7376673f7374796c653d666c6174)](https://www.versioneye.com/user/projects/553941560b24225ef6000002)

Take a look on [openhub.net](https://www.openhub.net/p/php_component_cli_arguments).

The current change log can be found [here](https://github.com/bazzline/php_component_cli_arguments/blob/master/CHANGELOG.md).

Install
=======

[](#install)

By Hand
-------

[](#by-hand)

```
mkdir -p vendor/net_bazzline/php_component_cli_arguments
cd vendor/net_bazzline/php_component_cli_arguments
git clone https://github.com/bazzline/php_component_cli_arguments .
```

With [Packagist](https://packagist.org/packages/net_bazzline/php_component_cli_arguments)
-----------------------------------------------------------------------------------------

[](#with-packagist)

```
composer require net_bazzline/php_component_cli_arguments:dev-master
```

Benefits
========

[](#benefits)

- easy up handling of following kinds of arguments
    - flags (command -f|--force)
    - lists (command --foobar=foo | command -f=foo)
    - values values (command )

Example
=======

[](#example)

Simple call [run.php](https://github.com/bazzline/php_component_cli_arguments/blob/master/Example/run.php) with tons of arguments like illustrated below.

```
php run.php --foo bar --foobar=foo --foobar="bar" -f="foo" -f=bar -b foobar foo -flag

```

Generates the following output.

```
arguments provided:
    --foo
    bar
    --foobar=foo
    --foobar=bar
    -f=foo
    -f=bar
    -b
    foobar
    foo
    -flag
flags provided:
    foo
    b
    f
    l
    a
    g
lists provided:
    foobar
        foo
        bar
    f
        foo
        bar
values provided:
    bar
    foobar
    foo

```

Terms
=====

[](#terms)

All arguments are grouped into one of three types, flags, lists or values. [Argument](http://en.wikipedia.org/wiki/Argument) or [parameter](http://en.wikipedia.org/wiki/Parameter)? I could not spot a major difference. When I think about parameters, my mind slipps into the domain of methods or functions, thats why I have decided to call them arguments. Furthermore, [php.net](http://php.net/manual/en/function.getopt.php) calls the "argument list" also :-).

Flag
----

[](#flag)

A flag is an argument that changes the behaviour of an command. It acts as a trigger so you can turn things on or off (best example in the world "-h|--help")

The position in a commandcall for a flag is not important, only the existence.

Valid flags are:

- -f
- --flag
- -flag (shortcut for -f -l -a -g)

List
----

[](#list)

A list is an argument that contains multiple values per name.

This call

```
php example.php --my_list="argument one" --my_list="argument two"

```

would result into a list with the name "my\_list" and two arguments, "argument one" and "argument two".

Lists are the most complex arguments. Like for flags, the position in a commandcall for a list usage is not important.

Valid Lists are:

- -l=value
- -l="val ue"
- --list=value
- --list="val ue"

Value
-----

[](#value)

Values are straight forward arguments. You simple pass them to your command. Instead of a flag or a list, the position is important.

Valid values are:

- value
- "val ue"

```
php example.php "value one" "value two"

```

First value has the content "value one", second value has the content "value two".

```
php example.php "value two" "value one"

```

First value has the content "value two", second value has the content "value one".

Short Name and Long Name Notation
---------------------------------

[](#short-name-and-long-name-notation)

Flag and list arguments supporting short name ("-f") and long name ("--foo") notation. A short name is indicated by a single "-" while a long name is indicated by a double "-". The handling and the support of them is domain specific (and also a matter of tast). To merge the usage and the content for lists is not part of this component.

Why no Validation?
==================

[](#why-no-validation)

Validation is a complex topic. That's why I decided to not put it into the domain of this component.
It would complicate the code itself. I would have created a universal validation interface that would slow down the usage of this component. Furthermore, you would have to learn a validation expression language or would have need to write code that fits my validation interface but not your "way of coding".

At the end, what is validation all about?

- check if a argument (flag, list, value) is passed or not
- if it is passed validate the value or if it is allowed under that circumstance (if it is right to use flag "-f" while also flag "-b" is passed etc.)
- if it is not passed but was mandatory, create a specific message or throw an exception (and the same for optional arguments)

To sum it up, validation is domain specific for the validation itself and the error handling. That's why I have decided to not support it deeply. The component supports your validation implementation with the methods "hasLists()", "hasList($name)" etc.

Since I won't write "never say never", if you have a smart idea or way to easy up validation, I'm open for an question or a pull request.

What about Optional Arguments?
==============================

[](#what-about-optional-arguments)

Optional arguments underlying the same problems as validation. It is not that easy to implement in an elegant way. It is very special/domain specific (e.g. an argument is optional if flag "--xyz" is used, otherwise mandatory). Your code has to take care if an argument is passed or not anyways. Using the available "has..."-methods should be sufficient and generic enough.

API
===

[](#api)

[API](http://www.bazzline.net/988fc4501e48d8aed30583f58a97f0d4c14ab2d3/index.html) is available at [bazzline.net](http://www.bazzline.net).

Other Great Components
======================

[](#other-great-components)

- [search on packagist](https://packagist.org/search/?search_query%5Bquery%5D=getopt)
- [yeriomin/getopt](https://github.com/yeriomin/getopt)
- [ulrichsg/getopt-php](https://github.com/ulrichsg/getopt-php)
- [stuartherbert/CommandLineLib](https://github.com/stuartherbert/CommandLineLib/)
- [auraphp/Aura.Cli](https://github.com/auraphp/Aura.Cli)
- [hoaproject/Console](https://github.com/hoaproject/Console)
- [deweller/php-cliopts](https://github.com/deweller/php-cliopts)

Final Words
===========

[](#final-words)

Star it if you like it :-). Add issues if you need it. Pull patches if you enjoy it. Write a blog entry if you use it :-D.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~231 days

Recently: every ~590 days

Total

13

Last Release

1318d ago

Major Versions

1.4.0 → 2.0.02018-01-12

PHP version history (4 changes)1.0.0PHP &gt;=5.3.3

1.4.0PHP ^5.6||^7.0

2.0.0PHP ~7.0

2.1.0PHP ~8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/58451b041f6f5a38c7e62762c96d01f5e2bcac30e322707fe4760a82bccb6856?d=identicon)[artodeto](/maintainers/artodeto)

---

Top Contributors

[![stevleibelt](https://avatars.githubusercontent.com/u/2287220?v=4)](https://github.com/stevleibelt "stevleibelt (47 commits)")

---

Tags

psrphpclishelltriggerlgplfree as in freedomPSR-4flagPHP7getoptargument

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/net-bazzline-php-component-cli-arguments/health.svg)

```
[![Health](https://phpackages.com/badges/net-bazzline-php-component-cli-arguments/health.svg)](https://phpackages.com/packages/net-bazzline-php-component-cli-arguments)
```

###  Alternatives

[seregazhuk/php-watcher

Automatically restart PHP application once the source code changes

395138.9k6](/packages/seregazhuk-php-watcher)[alecrabbit/php-console-spinner

Extremely flexible spinner for \[async\] php cli applications

24038.0k2](/packages/alecrabbit-php-console-spinner)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
