Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/palmtreephp/argparser

:palm_tree: Parse an array of arguments to call matching setter methods and/or merge with some defaults
https://github.com/palmtreephp/argparser

argparse argument-parser defaults

Last synced: about 1 month ago
JSON representation

:palm_tree: Parse an array of arguments to call matching setter methods and/or merge with some defaults

Awesome Lists containing this project

README

        

# Palmtree ArgParser

[![License](http://img.shields.io/packagist/l/palmtree/argparser.svg)](LICENSE)

Parse an array of arguments and call matching setters and/or merge with default arguments.

## Requirements
* PHP >= 7.1

## Installation

Use composer to add the package to your dependencies:
```bash
composer require palmtree/argparser
```

## Usage

```php
false,
];

private $name;
private $args = [];

public function __construct($args = []) {
$parser = new ArgParser($args);

$parser->parseSetters($this);
$this->args = $parser->resolveOptions(static::$defaultArgs);
}

public function setName($name) {
$this->name = $name;
}
}
```
```php
setName('Andy') and sets the force arg to true
$obj = new SomeClass([
'name' => 'Andy',
'force' => true,
]);
```

## License

Released under the [MIT license](LICENSE)