ali-eltaweel/command-parser 问题修复 & 功能扩展

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

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

ali-eltaweel/command-parser

最新稳定版本:1.2.0

Composer 安装命令:

composer require ali-eltaweel/command-parser

包简介

Shell-style Command-line Parser.

README 文档

README

Shell-style Command-line Parser

Installation

Install command-parser via Composer:

composer require ali-eltaweel/command-parser

Usage

Defining Commands

use CommandParser\Specs\{ Command, Operand, Option, OptionToken, OptionTokenType };

$git = new Command(

    name: 'git',
    description: 'Git command-line interface',
    options: [
        new Option(
            name: 'help',
            description: 'Display help information',
            isRepeatable: false,
            isFlag: true,
            tokens: [
                new OptionToken(token: 'help', type: OptionTokenType::Extended)
            ]
        )
    ],
    operands: [],
    subCommands: [
        new Command(
            name: 'commit',
            description: 'Record changes to the repository',
            options: [
                new Option(
                    name: 'message',
                    description: 'Use the given <msg> as the commit message',
                    isRepeatable: false,
                    isFlag: false,
                    tokens: [
                        new OptionToken(token: 'm', type: OptionTokenType::Short),
                        new OptionToken(token: 'message', type: OptionTokenType::Long)
                    ]
                )
            ],
            operands: [],
            subCommands: []
        ),
        new Command(
            name: 'push',
            description: 'Update remote refs along with associated objects',
            options: [
                new Option(
                    name: 'force',
                    description: 'Force update of the remote ref',
                    isRepeatable: false,
                    isFlag: true,
                    tokens: [
                        new OptionToken(token: 'f', type: OptionTokenType::Short),
                        new OptionToken(token: 'force', type: OptionTokenType::Long)
                    ]
                )
            ],
            operands: [
                new Operand(index: 0, name: 'remote', description: 'The remote repository to push to'),
                new Operand(index: 1, name: 'branch', description: 'The branch to push')
            ],
            subCommands: []
        )
    ]
);

Parsing Commands

use CommandParser\CommandLineParser;

$parser = new CommandLineParser();

$commandLine = $parser->parse(['git', 'commit', '-m', 'Initial commit'], $git);
$commandLine = $parser->parse(['git', 'push', 'origin', 'main'], $git);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2025-06-28