Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stk2k/argparser
Parser for command line options
https://github.com/stk2k/argparser
Last synced: 4 days ago
JSON representation
Parser for command line options
- Host: GitHub
- URL: https://github.com/stk2k/argparser
- Owner: stk2k
- License: mit
- Created: 2019-11-18T05:11:58.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-05T19:40:02.000Z (over 3 years ago)
- Last Synced: 2024-11-08T20:14:23.170Z (about 2 months ago)
- Language: PHP
- Size: 13.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Parser for command line options
=======================[![Latest Version on Packagist](https://img.shields.io/packagist/v/stk2k/argparser.svg?style=flat-square)](https://packagist.org/packages/stk2k/argparser)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Build Status](https://travis-ci.org/stk2k/argparser.svg?branch=master)](https://travis-ci.org/stk2k/argparser)
[![Coverage Status](https://coveralls.io/repos/github/stk2k/argparser/badge.svg?branch=master)](https://coveralls.io/github/stk2k/argparser?branch=master)
[![Code Climate](https://codeclimate.com/github/stk2k/argparser/badges/gpa.svg)](https://codeclimate.com/github/stk2k/argparser)
[![Total Downloads](https://img.shields.io/packagist/dt/stk2k/argparser.svg?style=flat-square)](https://packagist.org/packages/stk2k/argparser)## Description
Parser for command line options
## Feature
- No need to setup complex configuration
- short options: -abc means a/b/c switches(returns [a=>true, b=>true, c=>true])
- long options: --a-key value/--a-key=value returns associative array(['a-key'=>value])
- ordered options: "command a b c" returns ordered array([a, b, c])## Parameters
```php
ArgParser::parse(array $args = null, array $required =[], array $defaults = []);
```| arg name | explain |
| ---------------|----------------|
| $args | specify arguments(if omitted, global $argv is used) |
| $required | specify required options |
| $defaults | specify option default values |## Demo
### [01] Parse command line
```php
use stk2k\argparser\ArgParser;$args = ArgParser::parse(); // script.php a b -c --favorite-food="Fried potato"
print_r($args);
//Array
//(
// [0] => /path/to/script.php
// [1] => a
// [2] => b
// [-c] => 1
// [--favorite-food] => Fried potato
//)
```## Requirement
PHP 7.2 or later
## Installing stk2k/argparser
The recommended way to install stk2k/argparser is through
[Composer](http://getcomposer.org).```bash
composer require stk2k/argparser
```After installing, you need to require Composer's autoloader:
```php
require 'vendor/autoload.php';
```## License
[MIT](https://github.com/stk2k/argparser/blob/master/LICENSE)## Author
[stk2k](https://github.com/stk2k)
## Disclaimer
This software is no warranty.
We are not responsible for any results caused by the use of this software.
Please use the responsibility of the your self.