vaibhavpandeyvpz/clip
Composer 安装命令:
composer require vaibhavpandeyvpz/clip
包简介
Minimal and simple CLI library for PHP with zero required dependencies.
README 文档
README
CLI for PHP - A minimal and simple console application library for PHP with zero required dependencies.
Features
- 🚀 Zero dependencies - Only requires PHP 8.2+
- 📦 Minimal API - Simple and intuitive interface
- 🎨 Colored output - Built-in support for colored console output
- 💬 Interactive input - Ask questions, confirmations, and choices
- 🔧 Flexible - Easy to extend and customize
Installation
composer require vaibhavpandeyvpz/clip
Quick Start
<?php require_once __DIR__ . '/vendor/autoload.php'; use Clip\Console; use Clip\Commands\MyCommand; $app = new Console([ MyCommand::class, ]); exit($app->run());
Creating Commands
Create a command by extending the Command class:
<?php namespace Clip\Commands; use Clip\Command; use Clip\Stdio; class HelloWorld extends Command { public function getName(): string { return 'hello'; } public function getDescription(): string { return 'Say hello to the world'; } public function execute(Stdio $stdio): int { $name = $stdio->getArgument(0, 'World'); $stdio->writeln("Hello, {$name}!"); return 0; } }
Run the command:
php console hello # Output: Hello, World! php console hello Alice # Output: Hello, Alice!
Command Line Arguments
Arguments
Arguments are positional values passed to the command:
php console command arg1 arg2 arg3
Access them in your command:
$stdio->getArgument(0); // 'arg1' $stdio->getArgument(1); // 'arg2' $stdio->getArguments(); // ['arg1', 'arg2', 'arg3']
Options
Options are key-value pairs or flags:
php console command --name=John --verbose --force
Access them in your command:
$stdio->getOption('name'); // 'John' $stdio->getOption('verbose'); // true $stdio->hasOption('force'); // true $stdio->getOptions(); // ['name' => 'John', 'verbose' => true, 'force' => true]
Output Methods
Standard Output
$stdio->write('Message'); // Write without newline $stdio->writeln('Message'); // Write with newline $stdio->writeln(); // Write empty line
Colored Output
$stdio->error('Error message'); // Red $stdio->warning('Warning message'); // Yellow $stdio->info('Info message'); // Blue $stdio->debug('Debug message'); // Standard (no color) $stdio->verbose('Verbose message'); // Standard (no color)
Colors are automatically disabled when:
- Output is piped to a file
NO_COLORenvironment variable is set- Terminal doesn't support colors
Interactive Input
Ask for Input
$name = $stdio->ask('What is your name?', 'Guest'); // Prompts: What is your name? [Guest]: // Returns user input or 'Guest' if empty
Confirmations
if ($stdio->confirm('Do you want to continue?', true)) { // User confirmed (default: yes) } // Prompts: Do you want to continue? [Y/n]: // Accepts: y, yes, 1, true (case-insensitive)
Choices
$env = $stdio->choice( 'Select environment:', ['development', 'staging', 'production'], 'development' ); // Displays numbered list and returns selected choice
Complete Example
<?php namespace Clip\Commands; use Clip\Command; use Clip\Stdio; class Migrate extends Command { public function getName(): string { return 'migrate'; } public function getDescription(): string { return 'Run database migrations'; } public function execute(Stdio $stdio): int { $connection = $stdio->getOption('connection', 'default'); $force = $stdio->hasOption('force'); if ($force) { if (!$stdio->confirm('This will overwrite existing data. Continue?', false)) { $stdio->warning('Migration cancelled.'); return 1; } } $stdio->info("Running migrations with connection: {$connection}"); // Your migration logic here $stdio->writeln('Migrations completed successfully!'); return 0; } }
Usage:
php console migrate --connection=mysql php console migrate --connection=mysql --force
Requirements
- PHP 8.2 or higher
License
This project is open-sourced software licensed under the MIT license.
Author
Vaibhav Pandey
- Email: contact@vaibhavpandey.com
- GitHub: @vaibhavpandeyvpz
vaibhavpandeyvpz/clip 适用场景与选型建议
vaibhavpandeyvpz/clip 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 32 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 12 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cli」 「console」 「command」 「terminal」 「php8」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vaibhavpandeyvpz/clip 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vaibhavpandeyvpz/clip 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vaibhavpandeyvpz/clip 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This class provides you with an easy-to-use interface to progress bars.
A Wrapper for exec and it's results
Symfony bundle to monitor and execute commands
A Laravel package to retrieve data from Google Search Console
Additional artisan commands for Laravel
Shell command module for PHP.
统计信息
- 总下载量: 32
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 22
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-28