定制 blumfontein/command-line-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

blumfontein/command-line-php

最新稳定版本:v1.0.0

Composer 安装命令:

composer require blumfontein/command-line-php

包简介

PHP Command Line interface class. Provides friendly and flexible CLI argument parsing.

README 文档

README

PHP Command Line interface class. Provides friendly and flexible CLI argument parsing.

Usage

$args = CommandLine::parseArgs($_SERVER['argv']);

This command line option parser supports any combination of three types of options [single character options (-a -b or -ab or -c -d=dog or -cd dog), long options (--foo or --bar=baz or --bar baz) and arguments (arg1 arg2)] and returns a simple array.

[pfisher ~]$ php test.php --foo --bar=baz --spam eggs
  ["foo"]   => true
  ["bar"]   => "baz"
  ["spam"]  => "eggs"

[pfisher ~]$ php test.php -abc foo
  ["a"]     => true
  ["b"]     => true
  ["c"]     => "foo"

[pfisher ~]$ php test.php arg1 arg2 arg3
  [0]       => "arg1"
  [1]       => "arg2"
  [2]       => "arg3"

[pfisher ~]$ php test.php plain-arg --foo --bar=baz --funny="spam=eggs" --also-funny=spam=eggs \
> 'plain arg 2' -abc -k=value "plain arg 3" --s="original" --s='overwrite' --s
  [0]       => "plain-arg"
  ["foo"]   => true
  ["bar"]   => "baz"
  ["funny"] => "spam=eggs"
  ["also-funny"]=> "spam=eggs"
  [1]       => "plain arg 2"
  ["a"]     => true
  ["b"]     => true
  ["c"]     => true
  ["k"]     => "value"
  [2]       => "plain arg 3"
  ["s"]     => "overwrite"

Not supported: -cd=dog.

@author Patrick Fisher patrick@pwfisher.com

@since August 21, 2009

@see

Note: parseArgs.php contains a "minified" version of the same code, for your copypasta pleasure. For little scripts for which you want to have a nice interface.

统计信息

  • 总下载量: 2.78k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 13
  • 开发语言: PHP

其他信息

  • 授权协议: CC-BY-3.0
  • 更新时间: 2022-03-31