Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
PHP port of Python's optparse module
PHP
branch: master

This branch is 4 commits ahead, 7 commits behind lelutin:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
t
LICENSE
README.md
optparse.php

README.md

PHPOptparse -- A command-line option parser for PHP

PHPOptparse is a PHP port of Python's optparse module. Its interface tries to be as similar as possible to that of its Python counterpart.

How to use

Simply drop the optparse.php file in your project directory and include() it. Then, create an OptionParser object and add options with the add_option() method. When all options are set up, parse the options with the parse_args() method. The object returned from parse_args will contain all the values from the command line as attributes corresponding to names given to the "dest" parameter to add_option().

Example:

// called with: ./my_program -b 4

$option_parser = new OptionParser(array("version"=>"meuh 1.2.3", "description" => "lalla", "epilog"=>"patate"));
$option_parser->add_option(array(
    "-b", "--booh",
    "dest" => "gah",
    "metavar" => "<the thing>",
    "type" => "int"
));
$options = $option_parser->parse_args($argv);

// here $options->gah contains 4

Running the tests

The 't' directory contains unit tests for classes contained in the PHPOptparse library. To run the tests, use phpunit in the following manner:

phpunit OptionTest

License

The PHPOptparse library is licensed under the GNU GPLv2. The full license text should be shipped with the code in a file named LICENSE. If not, you can find the full text online at the following URL:

http://www.gnu.org/licenses/gpl-2.0.txt

Something went wrong with that request. Please try again.