apolinux/cmdcli 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

apolinux/cmdcli

最新稳定版本:v0.2.4

Composer 安装命令:

composer require apolinux/cmdcli

包简介

Parse CLI arguments and options

README 文档

README

Is a library created to parse command line options and arguments. This library reads command line string parts and map each option with an object. Also it can shows the help using option description.

Installation

composer require apolinux/cmdcli

Example

<?php

use Apolinux\CmdCli\CmdCli;

require_once __DIR__ . '/vendor/autoload.php';

$cmd_cli = new CmdCli('A command name');

$cmd_cli->addOpt(
  'xml',  // name of option
  CmdCli::TYPE_SINGLE_OPT,  // data type
  'is an xml option', // description
  'x', // short option, '-x'
  '--xml', // long option, '--xml' 
  false  ,    // require a parameter or not
  false      // is optional or not
)
->addArg(
  'logname' , // argument name
  'is a log name', // description
  true,  // is optional
);

$input = ['cmdname','-abc','-y','--sign','-x','file123.log'];

$text=$cmd_cli->parse($input);

// get options
$options = $cmd_cli->getParsedOpts();

// get arguments
$args = $cmd_cli->getParsedArgs();

// to know if one argument is defined. It shows true
var_dump($options['xml']);

// get argument value. It shows 'file123.log'
echo $args['logname'];

// other options not defined before are ignored

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-16