PHPackages                             jawira/mini-getopt - 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. jawira/mini-getopt

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

jawira/mini-getopt
==================

Very simple wrapper for getopt() function

v1.3.3(1y ago)23.2k12MITPHPPHP ^7.4 || ^8.0

Since Sep 19Pushed 1y ago1 watchersCompare

[ Source](https://github.com/jawira/mini-getopt)[ Packagist](https://packagist.org/packages/jawira/mini-getopt)[ RSS](/packages/jawira-mini-getopt/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (6)Versions (15)Used By (2)

Mini Getopt (a getopt wrapper)
==============================

[](#mini-getopt-a-getopt-wrapper)

Very simple wrapper for `getopt()` function.

[![Latest Stable Version](https://camo.githubusercontent.com/40bb38a20c89cba5986b366628da14da0478b26bba1caa05cf29a57a56272a14/68747470733a2f2f706f7365722e707567782e6f72672f6a61776972612f6d696e692d6765746f70742f76)](//packagist.org/packages/jawira/mini-getopt)[![composer.lock](https://camo.githubusercontent.com/7642e054c5bd863728a2376c9ff89b2313ff1e222882f98b3b170c0beb3fcf9f/68747470733a2f2f706f7365722e707567782e6f72672f6a61776972612f6d696e692d6765746f70742f636f6d706f7365726c6f636b)](//packagist.org/packages/jawira/mini-getopt)[![.gitattributes](https://camo.githubusercontent.com/c1ab1e9df6c6d6259a518dfef754d8306bd919afd4cada1aff223ca8b65e83c9/68747470733a2f2f706f7365722e707567782e6f72672f6a61776972612f6d696e692d6765746f70742f67697461747472696275746573)](//packagist.org/packages/jawira/mini-getopt)[![License](https://camo.githubusercontent.com/711f02c8c480608b91b087c21e2c3ec38c5be1b936dd7b40f0b0300aa088c0ad/68747470733a2f2f706f7365722e707567782e6f72672f6a61776972612f6d696e692d6765746f70742f6c6963656e7365)](//packagist.org/packages/jawira/mini-getopt)

Usage
-----

[](#usage)

This is only a wrapper, therefore the output from `mini-getopt` is going to be the same as `getopt()` function.

1. First you have to instantiate `\Jawira\MiniGetopt\MiniGetopt`.
2. Then you have to configure options you want to use. To do so use the following methods:

    - `MiniGetopt::addRequired`.
    - `MiniGetopt::addOptional`.
    - `MiniGetopt::addNoValue`.
3. To retrieve values you have to call one of the following method:

    - `MiniGetopt::getopt` returns the same as `getopt()`. Optionally you can pass `$optind` parameter.
    - `MiniGetopt::getOption` to get only one value.
    - `MiniGetopt::doc` get documentation.

Basic usage
-----------

[](#basic-usage)

PHP code:

```
// resources/example.php
// Preparing options
$mg = new \Jawira\MiniGetopt\MiniGetopt();
$mg->addRequired('f', 'format');    // value is required
$mg->addOptional('r', 'retry');     // value is optional
$mg->addOptional('q', '');          // only short option
$mg->addNoValue('v', 'verbose');    // no value
$mg->addNoValue('', 'version');     // only long option

// Calling getopt
var_export($mg->getopt());
```

Executing code:

```
$ php resources/example.php

array (
)
```

```
$ php resources/example.php -f=xml

array (
   'f' => 'xml',
)
```

```
$ php resources/example.php --format=xml -r -v

array (
  'format' => 'xml',
  'r' => false,
  'v' => false,
)
```

```
$ php resources/example.php -f=json -r=yes -v

array (
    'f' => 'json',
    'r' => 'yes',
    'v' => false,
)
```

```
$ php resources/example.php --retry -vvv

array (
  'retry' => false,
  'v' =>
  array (
    0 => false,
    1 => false,
    2 => false,
  ),
)
```

```
$ php resources/example.php --version=banana --invalid

array (
  'version' => false,
)
```

`optind` parameter
------------------

[](#optind-parameter)

```
// Setup
$mg = new \Jawira\MiniGetopt\MiniGetopt();
$mg->addRequired('f', 'format');
$mg->addNoValue('v', 'verbose');

// Calling getopt function with `optind` parameter
$optind = null;
$options = $mg->getopt($optind);
echo "optind: $optind" . PHP_EOL;
```

```
$ php resources/example.php --format=pdf -vv
optind: 3
```

Generate doc
------------

[](#generate-doc)

```
$mg = new \Jawira\MiniGetopt\MiniGetopt();
$mg->addRequired('f', 'format', 'Format to export', 'png|gif|svg');
$mg->addOptional('r', 'retry', 'Retry on error', 'count');
$mg->addOptional('q', '', 'Quiet mode', 'yes|no');
$mg->addNoValue('v', 'verbose', 'Display verbose messages');
$mg->addNoValue('', 'version', 'Show version');
echo $mg->doc();
```

```
$ php resource/example.php
OPTIONS

-f, --format=
Format to export

-r, --retry=[count]
Retry on error

-q=[yes|no]
Quiet mode

-v, --verbose
Display verbose messages

--version
Show version
```

How to install
--------------

[](#how-to-install)

```
$ composer install jawira/mini-getopt
```

Contributing
------------

[](#contributing)

If you liked this project, ⭐ star it on [GitHub](https://github.com/jawira/mini-getopt).

License
-------

[](#license)

This library is licensed under the [MIT license](LICENSE.md).

---

Packages from jawira
--------------------

[](#packages-from-jawira)

 [jawira/emoji-catalog ![GitHub stars](https://camo.githubusercontent.com/22510675fa5644c26212f855b959175260a169fce3b2df950b692923af91eacd/68747470733a2f2f62616467656e2e6e65742f6769746875622f73746172732f6a61776972612f656d6f6a692d636174616c6f673f69636f6e3d676974687562)](https://packagist.org/packages/jawira/emoji-catalog)Get access to +3000 emojis as class constants. [ jawira/plantuml-encoding ![GitHub stars](https://camo.githubusercontent.com/d074ddaf6ba2d98936493b11652343c4b3a1d171b642d5234a0ce32f6f5f3b59/68747470733a2f2f62616467656e2e6e65742f6769746875622f73746172732f6a61776972612f706c616e74756d6c2d656e636f64696e673f69636f6e3d676974687562)](https://packagist.org/packages/jawira/plantuml-encoding)PlantUML encoding functions. [jawira/case-converter ![GitHub stars](https://camo.githubusercontent.com/252838515757e452113329ed46602db164b1f5d2575da97f33367c34aa8a0eaf/68747470733a2f2f62616467656e2e6e65742f6769746875622f73746172732f6a61776972612f636173652d636f6e7665727465723f69636f6e3d676974687562)](https://packagist.org/packages/jawira/case-converter)Convert strings between 13 naming conventions: Snake case, Camel case, Pascal case, Kebab case, Ada case, Train case, Cobol case, Macro case, Upper case, Lower case, Sentence case, Title case and Dot notation. [more...](https://packagist.org/packages/jawira/)

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity74

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 ~186 days

Recently: every ~282 days

Total

13

Last Release

561d ago

Major Versions

v0.0.3 → v1.0.02019-10-10

PHP version history (4 changes)v0.0.3PHP ^7.0

v1.0.0PHP ^7.1

v1.1.0PHP &gt;=7.1

v1.3.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/496541?v=4)[Jawira Portugal](/maintainers/jawira)[@jawira](https://github.com/jawira)

---

Top Contributors

[![jawira](https://avatars.githubusercontent.com/u/496541?v=4)](https://github.com/jawira "jawira (96 commits)")

---

Tags

getoptphpcliterminaloptiongetopt

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jawira-mini-getopt/health.svg)

```
[![Health](https://phpackages.com/badges/jawira-mini-getopt/health.svg)](https://phpackages.com/packages/jawira-mini-getopt)
```

###  Alternatives

[symfony/console

Eases the creation of beautiful and testable command line interfaces

9.8k1.1B11.3k](/packages/symfony-console)[league/climate

PHP's best friend for the terminal. CLImate allows you to easily output colored text, special formats, and more.

1.9k14.0M273](/packages/league-climate)[php-school/cli-menu

A command line menu helper in PHP

2.0k1.1M27](/packages/php-school-cli-menu)[splitbrain/php-cli

Easy command line scripts for PHP with opt parsing and color output. No dependencies

177817.2k28](/packages/splitbrain-php-cli)[phalcon/cli-options-parser

Command line arguments/options parser.

181.0M7](/packages/phalcon-cli-options-parser)[php-tui/php-tui

Comprehensive TUI library heavily influenced by Ratatui

589747.0k6](/packages/php-tui-php-tui)

PHPackages © 2026

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