stk2k/argparser

命令行选项解析器

0.2.0 2021-06-05 19:39 UTC

This package is auto-updated.

Last update: 2024-09-06 03:03:26 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Code Climate Total Downloads

描述

命令行选项解析器

特性

  • 无需设置复杂的配置
  • 短选项:-abc 表示 a/b/c 开关(返回 [a=>true, b=>true, c=>true])
  • 长选项:--a-key value/--a-key=value 返回关联数组(['a-key'=>
  • 有序选项:"command a b c" 返回有序数组([a, b, c])

参数

ArgParser::parse(array $args = null, array $required =[], array $defaults = []);

演示

[01] 解析命令行

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
//)

要求

PHP 7.2 或更高版本

安装 stk2k/argparser

推荐通过 Composer 安装 stk2k/argparser。

composer require stk2k/argparser

安装后,您需要引入 Composer 的自动加载器

require 'vendor/autoload.php';

许可协议

MIT

作者

stk2k

免责声明

本软件无任何保证。

我们不承担因使用本软件而产生的任何后果。

请自行承担责任。