承接 posternak/commandeer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

posternak/commandeer

最新稳定版本:0.1.0

Composer 安装命令:

composer require posternak/commandeer

包简介

A fluent API to execute shell commands.

README 文档

README

A fluent PHP API for building and executing shell commands programmatically, for taking them under control, or in other words - commandeer them.

Installation

Install it into your project with composer:

composer require posternak/commandeer

Overview

Commandeer provides a type-safe, fluent API for constructing and executing shell commands in PHP, replacing error-prone string concatenation with chainable method calls.

ShellCommand Class

The foundation class that executes commands and captures results:

use Posternak\Commandeer\ShellCommand;

$command = new ShellCommand('git status');
$command->run();

if ($command->succeeded()) {
    $output = $command->getOutput(); // array of lines
}

API:

  • run(): self - Execute the command
  • succeeded(): bool - Check if exit code was 0
  • getOutput(): array - Get output lines
  • getCommand(): string - Get command string

Cmd Builder - Universal Command Builder

The Cmd class provides a universal interface for building any shell command, it's the fluent API. To construct a command:

  1. Start with the Cmd class.
  2. Call a static method whose name matches your desired executable (e.g., Cmd::docker() for the docker executable).
  3. Chain additional methods for CLI options and arguments, passing data as method parameters.

Method names are automatically converted to command-line syntax (underscores become dashes), and method arguments become command parameters.

Examples:

use Posternak\Commandeer\Builders\Cmd;

// docker ps -a
Cmd::docker()->ps()->_a()->run();

// kubectl get pods -o json
Cmd::kubectl()->get('pods')->_o('json')->run();

// npm install
Cmd::npm()->install()->run();

// git log --pretty oneline
Cmd::git()->log()->pretty('oneline')->run();

API:

  • Cmd::{executable}() - Start building a command for any executable
  • ->{method}() - Add command arguments (underscores become dashes)
  • ->run() - Execute the command
  • ->getCommand() - Preview command string without executing

Predefined Builders

For commonly-used tools, predefined builders eliminate the need to specify the executable name:

use Posternak\Commandeer\Builders\Git;
use Posternak\Commandeer\Builders\Composer;

// Instead of Cmd::git()
Git::status()->porcelain()->run();

// Instead of Cmd::composer()
Composer::require('vendor/package')->run();

Available builders: Git, Composer, Rector, PHPStan, PHPCsFixer, Php, Artisan

Git Convenience Methods

The Git builder includes shortcuts for common operations:

Git::addEverything(); // git add .
Git::commitWithMessage('feat: add feature'); // git commit -m "..."
Git::pushToOrigin('main'); // git push origin main

Interactive Shell (REPL)

Commandeer ships with an interactive shell for exploring and running commands without writing a PHP script. All builder classes are available automatically — no use statements needed.

vendor/bin/commandeer

Type help once inside to get started.

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固