rhdevelopment / arg-parser
Small, easy-to-use CLI argument parsing helpers for PHP scripts and cron tools.
v0.1.0
2025-10-23 20:47 UTC
Requires
- php: ^7.4 || ^8.0
Requires (Dev)
- phpunit/phpunit: ^9
- roave/security-advisories: dev-latest
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)