Skip to content

Commit

Permalink
rename Getopt class to GetOpt
Browse files Browse the repository at this point in the history
  • Loading branch information
tflori committed Jul 24, 2017
1 parent cb37fea commit 0b98797
Show file tree
Hide file tree
Showing 29 changed files with 245 additions and 245 deletions.
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ Features:
* php 5.3 support dropped (solves #72)
* moved to neutral namespace `GetOpt`
* parse options after operands (gnu compatibility; solves #39)
* added `Getopt::MULTIPLE_ARGUMENT` for parameter aggregation (solves #57)
* added `GetOpt::MULTIPLE_ARGUMENT` for parameter aggregation (solves #57)
* implemented `Command` for kinda routing in console applications (solves #41)
* added `HelpInterface` for custom help implementations
* refactored `Getopt::getHelpText()` for better support of other features and customization
* refactored `GetOpt::getHelpText()` for better support of other features and customization

Bugfixes:
* `Getopt::count()` returns the wrong value (solves #70)
* `GetOpt::count()` returns the wrong value (solves #70)

## 2.4.3 (2017-07-02)

Expand Down Expand Up @@ -58,7 +58,7 @@ Features:
## 2.0.0-RC.1 (2014-01-17)

Changes:
* Namespace is now Ulrichsg\Getopt
* Namespace is now Ulrichsg\GetOpt
* Public API has been cleaned up, please refer to the documentation


Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Getopt.PHP
# GetOpt.PHP

[![Build Status](https://travis-ci.org/getopt-php/getopt-php.svg?branch=master)](https://travis-ci.org/getopt-php/getopt-php)
[![Coverage Status](https://coveralls.io/repos/github/getopt-php/getopt-php/badge.svg?branch=master)](https://coveralls.io/github/getopt-php/getopt-php?branch=master)
[![Latest Stable Version](https://poser.pugx.org/ulrichsg/getopt-php/v/stable.svg)](https://packagist.org/packages/ulrichsg/getopt-php)
[![Total Downloads](https://poser.pugx.org/ulrichsg/getopt-php/downloads.svg)](https://packagist.org/packages/ulrichsg/getopt-php)
[![License](https://poser.pugx.org/ulrichsg/getopt-php/license.svg)](https://packagist.org/packages/ulrichsg/getopt-php)

Getopt.PHP is a library for command-line argument processing. It supports PHP version 5.4 and above.
GetOpt.PHP is a library for command-line argument processing. It supports PHP version 5.4 and above.

## Features

Expand All @@ -26,4 +26,4 @@ Getopt.PHP is a library for command-line argument processing. It supports PHP ve

## License

Getopt.PHP is published under the [MIT License](http://www.opensource.org/licenses/mit-license.php).
GetOpt.PHP is published under the [MIT License](http://www.opensource.org/licenses/mit-license.php).
2 changes: 1 addition & 1 deletion docs/_layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<body>
<div class="wrapper">
<header>
<h2>Getopt.php<br /><small>a better getopt for php</small></h2>
<h2>GetOpt.php<br /><small>a better getopt for php</small></h2>

<menu>
<ul>
Expand Down
10 changes: 5 additions & 5 deletions docs/advanced/argument-validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ permalink: /advanced/argument-validation.html
---
# {{ page.title }}

You can have Getopt check the validity of an option argument by assigning it a
You can have GetOpt check the validity of an option argument by assigning it a
[callable](http://www.php.net/manual/en/language.types.callable.php) validation function:

```php?start_inline=true
$getopt = new Getopt(array(
(new Option('a', null, Getopt::REQUIRED_ARGUMENT))
$getopt = new GetOpt(array(
(new Option('a', null, GetOpt::REQUIRED_ARGUMENT))
->setValidation(function($value) {
return ($value > 9000);
})
Expand All @@ -27,8 +27,8 @@ If you want an option to have both a validation function and a
by creating an `Argument` object directly:

```php?start_inline=true
$getopt = new Getopt(array(
(new Option('n', null, Getopt::REQUIRED_ARGUMENT))
$getopt = new GetOpt(array(
(new Option('n', null, GetOpt::REQUIRED_ARGUMENT))
->setArgument(new Argument(10, 'is_numeric'))
));
```
14 changes: 7 additions & 7 deletions docs/advanced/default-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ You can assign a default value to any option that can take an argument. Then if
command line, it will assume the default value instead of `null`.

```php?start_inline=true
$getopt = new Getopt(array(
(new Option('n', null, Getopt::REQUIRED_ARGUMENT))
$getopt = new GetOpt(array(
(new Option('n', null, GetOpt::REQUIRED_ARGUMENT))
->setDefaultValue(10)
));
```
Expand All @@ -22,20 +22,20 @@ If you want an option to have both a default value and a
by creating an `Argument` object directly:

```php?start_inline=true
$getopt = new Getopt(array(
(new Option('n', null, Getopt::REQUIRED_ARGUMENT))
$getopt = new GetOpt(array(
(new Option('n', null, GetOpt::REQUIRED_ARGUMENT))
->setArgument(new Argument(10, 'is_numeric'))
));
```

## The Legacy Way

If you are using the array notation from Getopt v1, you can set the default value as the fifth
If you are using the array notation from GetOpt v1, you can set the default value as the fifth
element of the option array. Note that this forces you to set a
[description](option-descriptions.md), though you can leave it blank:

```php?start_inline=true
$getopt = new Getopt(array(
array('n', null, Getopt::REQUIRED_ARGUMENT, '', 10)
$getopt = new GetOpt(array(
array('n', null, GetOpt::REQUIRED_ARGUMENT, '', 10)
));
```
12 changes: 6 additions & 6 deletions docs/advanced/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ permalink: /advanced/
---
# {{ page.title }}

These optional features add more power to Getopt in exchange for some additional configuration work.
These optional features add more power to GetOpt in exchange for some additional configuration work.

One thing all of these have in common is that they make use of chainable methods. That makes it easy to add any
number of them to an `Option` object, for example (PHP 5.4 and above only):

```php?start_inline=true
$getopt = new Getopt(array(
(new Option('o', 'option', Getopt::REQUIRED_ARGUMENT)) // note the extra set of parentheses
$getopt = new GetOpt(array(
(new Option('o', 'option', GetOpt::REQUIRED_ARGUMENT)) // note the extra set of parentheses
->setDescription('Description of option')
->setDefaultValue('default')
));
```

As of Getopt 2.2, users restricted to PHP 5.3 (where chaining methods directly off the constructor is not supported
As of GetOpt 2.2, users restricted to PHP 5.3 (where chaining methods directly off the constructor is not supported
yet) can use the static `create()` method instead:

```php?start_inline=true
$getopt = new Getopt(array(
Option::create('o', 'option', Getopt::REQUIRED_ARGUMENT)
$getopt = new GetOpt(array(
Option::create('o', 'option', GetOpt::REQUIRED_ARGUMENT)
->setDescription('Description of option')
->setDefaultValue('default')
));
Expand Down
12 changes: 6 additions & 6 deletions docs/advanced/option-descriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ You can add short description texts to individual options. They will be used to
[generated help text]({{ site.baseurl}}/basic/usage-information.html).

```php?start_inline=true
$getopt = new Getopt(array(
$getopt = new GetOpt(array(
(new Option('v', 'version'))
->setDescription('Display version information'),
(new Option('h', 'help'))
Expand All @@ -24,20 +24,20 @@ requires manual creation of an `Argument` object. For instance, the following sn
option show up as `-n <count>` (instead of `-n <arg>`):

```php?start_inline=true
$getopt = new Getopt(array(
(new Option('n', null, Getopt::REQUIRED_ARGUMENT))
$getopt = new GetOpt(array(
(new Option('n', null, GetOpt::REQUIRED_ARGUMENT))
->setArgument(new Argument(null, null, "count"))
// see "Argument Validation" for the meaning of the first two parameters
));
```

## The Legacy Way

If you are using the array notation from Getopt v1, you can set the description as the fourth
If you are using the array notation from GetOpt v1, you can set the description as the fourth
element of the option array:

```php?start_inline=true
$getopt = new Getopt(array(
array('v', 'version', Getopt::NO_ARGUMENT, 'Display version information')
$getopt = new GetOpt(array(
array('v', 'version', GetOpt::NO_ARGUMENT, 'Display version information')
));
```
16 changes: 8 additions & 8 deletions docs/basic/example-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ permalink: /basic/example-code.html
---
# {{ page.title }}

This short (and incomplete) sample program demonstrates the use of Getopt's basic features. It is modeled after
This short (and incomplete) sample program demonstrates the use of GetOpt's basic features. It is modeled after
[GNU mkdir](http://unixhelp.ed.ac.uk/CGI/man-cgi?mkdir) as an example of a real-world command line
interface that uses many of the aspects featured in Getopt.
interface that uses many of the aspects featured in GetOpt.

```php
<?php

use Ulrichsg\Getopt\Getopt;
use Ulrichsg\Getopt\Option;
use Ulrichsg\GetOpt\GetOpt;
use Ulrichsg\GetOpt\Option;

$getopt = new Getopt(array(
new Option('m', 'mode', Getopt::REQUIRED_ARGUMENT),
$getopt = new GetOpt(array(
new Option('m', 'mode', GetOpt::REQUIRED_ARGUMENT),
new Option('p', 'parents'),
new Option('v', 'verbose'),
new Option('Z', 'context', Getopt::REQUIRED_ARGUMENT),
new Option('Z', 'context', GetOpt::REQUIRED_ARGUMENT),
new Option(null, 'help'),
new Option(null, 'version')
));
Expand All @@ -28,7 +28,7 @@ try {
$getopt->parse();

if ($getopt['version']) {
echo "Getopt example v0.0.1\n";
echo "GetOpt example v0.0.1\n";
exit(0);
}

Expand Down
6 changes: 3 additions & 3 deletions docs/basic/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ permalink: /basic/
---
# {{ page.title }}

These pages describe Getopt's essential features. They cover everything you need to know in order to make use of it.
These pages describe GetOpt's essential features. They cover everything you need to know in order to make use of it.
All of the advanced features are optional; you only need to look into them if you actually want to use them.

## Topics

**[Specifying options](specifying-options.md)** - The first step of using Getopt: configuring the desired options
**[Specifying options](specifying-options.md)** - The first step of using GetOpt: configuring the desired options

**[Retrieving values](retrieving-values.md)** - The second step of using Getopt: invoking the parser and retrieving the
**[Retrieving values](retrieving-values.md)** - The second step of using GetOpt: invoking the parser and retrieving the
results

**[Usage information](usage-information.md)** - Generate usage information for help texts automatically
Expand Down
8 changes: 4 additions & 4 deletions docs/basic/retrieving-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ permalink: /basic/retrieving-values.html
---
# {{ page.title }}

After you have constructed your `Getopt` object and specified all your options, you have to invoke the parser
After you have constructed your `GetOpt` object and specified all your options, you have to invoke the parser
next. In the usual case this looks just like this:

```php?start_inline=true
$getopt->parse();
```

By default, Getopt looks for command line arguments in the superglobal variable `$GLOBALS['argv']`. You can override
By default, GetOpt looks for command line arguments in the superglobal variable `$GLOBALS['argv']`. You can override
this behavior by passing a string or array.

After that (and if no error occurred - see below for that case) you can use the following methods:
Expand Down Expand Up @@ -57,7 +57,7 @@ $getopt->getOperands();

## Error Handling

If the command line arguments do not match the specified options, `Getopt::parse()` will throw a standard
If the command line arguments do not match the specified options, `GetOpt::parse()` will throw a standard
`UnexpectedValueException` with a message containing detailed information about what went wrong. Catching
this exception thus allows you to react to the error the way you prefer (you could, for instance, use
`Getopt::getHelpText()` to print [usage information](usage-information.md)).
`GetOpt::getHelpText()` to print [usage information](usage-information.md)).
30 changes: 15 additions & 15 deletions docs/basic/specifying-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ is no argument.
**Note:** An option does not need to have both a long and a short name. Either name may be disabled by
setting it to `null`.

Getopt.php offers multiple ways to specify options. Which one you should choose depends on the set of features you
GetOpt.php offers multiple ways to specify options. Which one you should choose depends on the set of features you
want to use.

## The Original Way (Short Options Only)

This uses the exact same syntax as [PHP's `getopt()` function](http://php.net/manual/en/function.getopt.php)
(and the original GNU getopt). It is the shortest way to set up Getopt, but it does not support
(and the original GNU getopt). It is the shortest way to set up GetOpt, but it does not support
long options or any advanced features:

```php?start_inline=true
$getopt = new Getopt('ab:c::');
$getopt = new GetOpt('ab:c::');
```

Each letter or digit in the string declares one option. Letters may be followed by either one or two colons to
Expand All @@ -40,39 +40,39 @@ determine if the option can or must have an argument:

## The Explicit Way

This way has been newly introduced in version 2.0 of Getopt and is the only one that grants access to all advanced
features. It involves manually creating `Option` objects and passing them to the Getopt constructor:
This way has been newly introduced in version 2.0 of GetOpt and is the only one that grants access to all advanced
features. It involves manually creating `Option` objects and passing them to the GetOpt constructor:

```php?start_inline=true
$getopt = new Getopt(array(
new Option('a', 'alpha', Getopt::REQUIRED_ARGUMENT),
new Option(null, 'beta', Getopt::OPTIONAL_ARGUMENT),
$getopt = new GetOpt(array(
new Option('a', 'alpha', GetOpt::REQUIRED_ARGUMENT),
new Option(null, 'beta', GetOpt::OPTIONAL_ARGUMENT),
new Option('c', null)
));
```

The three arguments of the `Option` constructor are the same as described above: short name, long name and mode.
Either long or short name can be null. For the mode use one of the three class constants `Getopt::REQUIRED_ARGUMENT`,
`Getopt::OPTONAL_ARGUMENT` or `Getopt::NO_ARGUMENT`. The latter can be omitted as it is the default value.
Either long or short name can be null. For the mode use one of the three class constants `GetOpt::REQUIRED_ARGUMENT`,
`GetOpt::OPTONAL_ARGUMENT` or `GetOpt::NO_ARGUMENT`. The latter can be omitted as it is the default value.

## The Legacy Way

This is how long names and advanced features could be accessed in Getopt v1. It still works, but is considered
This is how long names and advanced features could be accessed in GetOpt v1. It still works, but is considered
deprecated and will not support future features, thus it should not be used anymore.

This way is very similar to the explicit way, except that the three option arguments are placed in an array:

```php?start_inline=true
$getopt = new Getopt(array(
array('a', 'alpha', Getopt::REQUIRED_ARGUMENT),
array(null, 'beta', Getopt::OPTIONAL_ARGUMENT),
$getopt = new GetOpt(array(
array('a', 'alpha', GetOpt::REQUIRED_ARGUMENT),
array(null, 'beta', GetOpt::OPTIONAL_ARGUMENT),
array('c', null)
));
```

## Adding more options

If you want to add options to an existing `Getopt` object, you can do so by calling `addOptions()`.
If you want to add options to an existing `GetOpt` object, you can do so by calling `addOptions()`.
It takes the same types of arguments as the constructor. If you give it an option with the same name(s) as an already
existing one, the latter will be overwritten. Passing an option where only one name is equal to an existing
option's, but the other one is different, will result in an exception.
2 changes: 1 addition & 1 deletion docs/basic/usage-information.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ permalink: /basic/usage-information.html
---
# {{ page.title }}

Getopt can automatically generate a human-readable usage information from the specified options. Use it for quickly
GetOpt can automatically generate a human-readable usage information from the specified options. Use it for quickly
setting up help texts:

```php?start_inline=true
Expand Down
8 changes: 4 additions & 4 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ permalink: /development.html
---
# {{ page.title }}

Getopt has received contributions from [several people](https://github.com/getopt-php/getopt-php/graphs/contributors)
GetOpt has received contributions from [several people](https://github.com/getopt-php/getopt-php/graphs/contributors)
in the past, for which we are deeply thankful. If you would like to contribute, feel free to
[create an issue](https://github.com/getopt-php/getopt-php/issues/new) or clone the source and submit a pull
request. If you are planning to hack on Getopt yourself, please read the rest of this page for some general
request. If you are planning to hack on GetOpt yourself, please read the rest of this page for some general
information.

## Guidelines

- Getopt supports PHP versions back up to 5.4, so unfortunately, all those shiny language features from newer
- GetOpt supports PHP versions back up to 5.4, so unfortunately, all those shiny language features from newer
versions are off limits. Luckily, [Travis](https://travis-ci.org/getopt-php/getopt-php) ensures this
automatically and will notify you if your pull request does not respect it (or if it breaks anything else).
- With v2.0 we have adopted [PSR-2](http://www.php-fig.org/psr/psr-2/) as coding conventions, so we would
Expand All @@ -31,7 +31,7 @@ However, if it is not, you can pull it in as a local dependency by running:
$ make install-dependencies
```

This will download Composer and then run it to install Getopt's development dependencies (i.e. PHPUnit). After that,
This will download Composer and then run it to install GetOpt's development dependencies (i.e. PHPUnit). After that,
the test suite can be executed like this:

```console
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ permalink: /
---
# {{ page.title }}

Getopt.php is a command-line argument processor for PHP 5.4 and above. It started out as an object-oriented
GetOpt.php is a command-line argument processor for PHP 5.4 and above. It started out as an object-oriented
replacement for PHP's own <a href="http://php.net/manual/en/function.getopt.php">`getopt()`</a> method,
but has since evolved to become significantly more powerful.

Expand Down

0 comments on commit 0b98797

Please sign in to comment.