Argh! PHP Argument Helper. Easily parse all types of command line arguments in PHP CLI scripts.

1.0.3-beta 2019-04-30 21:47 UTC

This package is auto-updated.

Last update: 2024-09-29 05:08:34 UTC


README

"Argh" is short for Argument Helper.

Interpret PHP command line arguments with ease so you can focus on your CLI application.

Scrutinizer Code Quality

Build Status

System Requirements

This project has been developed and tested with the following (see list below), and has yet to be tested using other operating systems or versions of PHP.

  • PHP 7.2.14
  • CentOS 7.6

Installing

There are two methods of installing Argh. Composer is recommended.

  1. Composer
  2. Phar (PHP Archive)

More detailed instructions can be found at Argh Installation Instructions

Composer Installation

Composer is the preferred method for installation.

$ composer require netfocusinc/argh

$ php vendor/netfocusinc/argh/bin/argh.php about
Argh! by Benjamin Hough, Net Focus Inc. - https://www.netfocusinc.com/argh

Phar (PHP Archive)

Releases can be downloaded from Argh's Github Releases.

$ cd path/to/argh
$ php argh.phar about
Argh! by Benjamin Hough, Net Focus Inc. - https://www.netfocusinc.com/argh

Basic Usage

Using Argh is an easy way to interpret command line arguments in your PHP CLI scripts.

When your PHP CLI script is invoked with command line arguments $ php myprogram.php --message='Hello World!'

<?php

include 'vendor/autoload.php';

use netfocusinc\argh\Argh;
use netfocusinc\argh\StringParameter;

// Create a new Argh instance
$argh = new Argh(
  [
    StringParameter::createWithAttributes( [ 'name' => 'message' ] )		
  ]
);

// Let Argh parse PHP's $argv array
$argh->parse($argv);

// Access run-time values of the arguments that were supplied to your CLI script
echo $argh->message; // Hello World!

See more examples of how to use Argh are available.

Running Unit Tests

The PHPUnit tests for Argh can be run like this.

$ vendor/bin/phpunit --bootstrap vendor/autoload.php --testdox tests/

Built With

  • PHP - PHP is a popular general-purpose scripting language that is especially suited to web development.
  • Composer - Dependency Manager for PHP
  • PHPUnit - Testing Framework
  • phar-composer - Simple phar creation for any project managed via composer.

Versioning

This project uses Semantic Versioning

For the versions available, see the GitHub releases page.

A Changelog is also available on Github.

Authors

See the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.