PHPackages                             amercier/cli-helpers - 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. amercier/cli-helpers

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

amercier/cli-helpers
====================

Utility classes to write PHP command-line scripts

v1.4.5(8y ago)258.8k—0%2[1 PRs](https://github.com/amercier/php-cli-helpers/pulls)ISCPHPPHP &gt;=5.3

Since Jul 31Pushed 2y ago3 watchersCompare

[ Source](https://github.com/amercier/php-cli-helpers)[ Packagist](https://packagist.org/packages/amercier/cli-helpers)[ Docs](https://github.com/amercier/php-cli-helpers)[ RSS](/packages/amercier-cli-helpers/feed)WikiDiscussions master Synced today

READMEChangelog (5)Dependencies (3)Versions (11)Used By (0)

php-cli-helpers
===============

[](#php-cli-helpers)

Utility classes to write PHP command-line scripts

[![Build Status](https://camo.githubusercontent.com/370071f7c882e78b38ff0698b2994b88af71c5f9388f379f86a46c08ac48beeb/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f616d6572636965722f7068702d636c692d68656c706572732f6d61737465722e7376673f7374796c653d666c6174)](https://travis-ci.org/amercier/php-cli-helpers)[![Code Climate](https://camo.githubusercontent.com/36b30c2257efcfddf5acae6a6001c9083028120fd02837a7d8ce9518b69b6451/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f6769746875622f616d6572636965722f7068702d636c692d68656c706572732e7376673f7374796c653d666c6174)](https://codeclimate.com/github/amercier/php-cli-helpers)[![Test Coverage](https://camo.githubusercontent.com/41dfad75fd26f7a1b827fa382a7672611d71657de1876cd5d5620b2dcd0a6618/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f636f7665726167652f6769746875622f616d6572636965722f7068702d636c692d68656c706572732e7376673f7374796c653d666c6174)](https://codeclimate.com/github/amercier/php-cli-helpers)[![Dependency Status](https://camo.githubusercontent.com/6dc86f4d00de7528cd5932ea7dcdd26cc5974aa2c506fd475cd72cc42513fcd4/68747470733a2f2f696d672e736869656c64732e696f2f67656d6e617369756d2f616d6572636965722f7068702d636c692d68656c706572732e7376673f7374796c653d666c6174)](https://gemnasium.com/amercier/php-cli-helpers)

[![Latest Stable Version](https://camo.githubusercontent.com/3eafe2cb28cae74136a79604cb74db9af21c758334563233627d7c0c83d61088/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616d6572636965722f636c692d68656c706572732e737667)](https://packagist.org/packages/amercier/cli-helpers)[![PHP version](https://camo.githubusercontent.com/9db00ee9f72c5cb716564df75d636b773e4bfccec9b0deb9640fde9c8f53e092/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f616d6572636965722f636c692d68656c706572732e737667)](https://packagist.org/packages/amercier/cli-helpers)[![License](https://camo.githubusercontent.com/8fbb64bdf172bf04650f0ff578465c043d2f8aeb4c92a1abe76d4232980a8cb2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616d6572636965722f636c692d68656c706572732e737667)](https://packagist.org/packages/amercier/cli-helpers)

Installation
------------

[](#installation)

*php-cli-helpers* is available through [Composer](http://getcomposer.org/).

```
  "require": {
    "amercier/cli-helpers": "1.*"
  }
```

```
php composer.phar install
```

If you are not familiar with *Composer*, please read the [full installation intructions](docs/install.md).

Usage
-----

[](#usage)

### \\Cli\\Helpers\\Parameter

[](#clihelpersparameter)

Utility class to handle command-line parameters.

```
$options = \Cli\Helpers\Parameter::getFromCommandLine(array(
    'host'     => new Parameter('h', 'host'    , '127.0.0.1'),
    'username' => new Parameter('u', 'username', Parameter::VALUE_REQUIRED),
    'password' => new Parameter('p', 'password', Parameter::VALUE_REQUIRED),
    'verbose'  => new Parameter('v', 'verbose' , Parameter::VALUE_NO_VALUE),
));

$options['host'];     // given -h/--host, or 127.0.0.1 otherwise
$options['username']; // given -u/--username
$options['password']; // given -p/--password
$options['verbose'];  // true if -v/--verbose is given, false otherwise
```

See [API Documentation for Parameter](docs/api-parameter.md)

### \\Cli\\Helpers\\Script and \\Cli\\Helpers\\DocumentedScript

[](#clihelpersscript-and-clihelpersdocumentedscript)

Utility class to write scripts as objects.

```
#!/usr/bin/env php
