rhdevelopment/arg-parser

Small, easy-to-use CLI argument parsing helpers for PHP scripts and cron tools.

Maintainers

Package info

github.com/hadley8899/arg-parser

pkg:composer/rhdevelopment/arg-parser

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2025-10-23 20:47 UTC

This package is auto-updated.

Last update: 2026-03-24 11:13:46 UTC


README

Small, easy-to-use CLI argument parsing helpers for PHP scripts and cron tools.

Usage sketch:

use RHDevelopment\ArgParser\ArgParser;

ArgParser::option('name')->required()->asInt();
ArgParser::option('verbose');

$values = ArgParser::parse();
// $values is an associative array of parsed options

Interactive prompting helper

This package provides a small prompt() helper for interactive scripts. It reads from STDIN and returns the trimmed input. If you provide a default value and the user submits an empty line the default will be returned.

Example (see bin/example.php):

use RHDevelopment\ArgParser\ArgParser;

ArgParser::option('name')->asString();
ArgParser::option('count')->asInt()->default(1);
ArgParser::option('verbose');

$values = ArgParser::parse();
if (empty($values['name'])) {
    $values['name'] = ArgParser::prompt('Enter your name', 'guest');
}

Run the provided example script (make it executable first):

chmod +x bin/example.php
./bin/example.php --verbose --count=3

Run tests:

composer install
composer test

License: MIT (see LICENSE)