定制 alphayax/get_opt 二次开发

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

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

alphayax/get_opt

最新稳定版本:3.1.0

Composer 安装命令:

composer require alphayax/get_opt

包简介

Utility class for manage scripts arguments

README 文档

README

A library to manage scripts arguments

Latest Stable Version Latest Unstable Version pakagist

Travis Coverage Status Codacy Badge

License Total Downloads

Features

  • Singleton pattern
  • Auto generate help
  • Manage short and long option (-a --abc)
  • Manage values and multiple values (-v /toto -v /tutu)
  • Manage required options

Examples

Check if a parameter (specified via a letter or a name) is set

$Args = \alphayax\utils\cli\GetOpt::getInstance();
$Args->setDescription('This script is a tiny example to show library features');
$verboseOption = $Args->addOpt('v', 'verbose', 'Verbose Mode');

$Args->parse();

$isVerboseMode = $verboseOption->isPresent();

Get the value of the --file option

$Args = \alphayax\utils\cli\GetOpt::getInstance();
$Args->setDescription('This script is a tiny example to show library features');
$fileOption = $Args->addOpt('f', 'file', 'File name', true);

$Args->parse();

// Check if file option is specified (via -f or --file)
if( $fileOption->isPresent()){
    $fileName = $fileOption->getValue();
}

Auto-generated Help

Example of help output (if the -h or --help flag is specified) :

   Description
   	This script is a tiny example to show library features
   
   Usage
   	/usr/bin/php a.php [OPTIONS]
   
   Options
	-d        	              	Debug mode
	          	--dry-run     	Dry Run mode
	          	--file <value>	Specify the file name
	-h        	--help        	Display help
	-n <value>	              	[REQUIRED] Number of lines
	-v        	--verbose     	Verbose Mode

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-2.1
  • 更新时间: 2016-06-18