scf/simple-command-factory
Composer 安装命令:
composer create-project scf/simple-command-factory
包简介
The Simple Command Factory.
关键字:
README 文档
README
Simple Command Factory
scf is a simple, small, lightweight command factory. It comes with a command to help boilerplate the creation of more commands, and enough features to get more small tasks completed. Feel free to create issues / contribute!.
Quick Highlight
- I am using this in some current home projects I work on, so I will make sure to maintain package stablility starting at v1.0.0
- This was inspired by Laravels Artisan command and the Symfony Command line packages as well.
Install:
# composer create-project scf/simple-command-factory <app> composer create-project scf/simple-command-factory simple-command-factory # or git clone https://github.com/joshuaGlass808/simple-command-factory.git cd simple-command-factory/ composer install
After that, feel free to start creating commands:
./scf create:command --command-name='ExampleCommand' --signature='print:message' # or php scf create:command --command-name='ExampleCommand' --signature='print:message'
Running the command above will result in this output:
Building file: simple-command-factory/app/Commands/ExampleCommand.php
New class (test) create: simple-command-factory/app/Commands/ExampleCommand.php
Don't forget to add ExampleCommand to the App/Kernel class.
Which creates a file like this:
<?php namespace App\Commands; use SCF\Contracts\CommandContract; use SCF\Commands\BaseCommand; use SCF\Traits\CommandTrait; class ExampleCommand extends BaseCommand implements CommandContract { use CommandTrait; public string $signature = 'print:message'; public array $argumentMap = []; public function execute(): void { // Get started! } }
Example command class:
This repo ships with an example command already set up in the App\Commands namespace.
Feel free to use it!
<?php declare(strict_types=1); namespace App\Commands; use SCF\Contracts\CommandContract; use SCF\Commands\BaseCommand; use SCF\Traits\CommandTrait; use SCF\Styles\TextStyle; class ExampleCommand extends BaseCommand implements CommandContract { use CommandTrait; public string $signature = 'print:message'; public array $argumentMap = [ '--message=' => 'Message to be printed', '--show' => 'For boolean style flags, leave out the = at the end. Default is false unless used' ]; /** * Method called to run the command. */ public function execute(): void { // Get started! $start = microtime(true); $args = $this->getArgs(); if ($args['show']) { $start = microtime(true); $this->success("Message: {$args['message']}\n"); } $this->warn("Environment: {$this->env['ENV']}\n"); $this->warn("Config DB Driver: {$this->config['database-driver']}\n"); $this->output('Execution took: ' . (microtime(true) - $start) . " seconds\n", TextStyle::CYAN); } }
Before we can use this, make sure we register it in App\Kernel.
In Kernel.php:
use App\Commands\ExampleCommand;
...
/** * Register your Commands here. */ const COMMANDS = [ ExampleCommand::class, ];
Example usage:
./scf -h ./scf --help ./scf create:command --command-name='DesktopImageRotator' ./scf print:message --message='hello world' --show # # OUTPUT: hello world # without the --show flag, show will default to false and not show the message ./scf print:message --message='hello world'
Once you register that new commands in the Kernel you will be able to see them inside of the help message
Example help:
$ ./scf -h Usage: ./scf <command:signature> [--args=...] ./scf -h create:command --path= : override default path (app/Commands/). --command-name= : Name of the command class you wish to create. --signature= : set the signature print:message --message= : Message to be printed --show : For boolean style flags, leave out the = at the end. Default is false unless used Options: --help|-h : Display this help message.
Documentation
Somethings that may not have been shown in the examples above:
- Colored text in command classes
$this->output('string', TextColor::CYAN);$this->warn('Outputs yellow text');$this->success('Outputs green text');$this->error('Outputs red text');$this->error('String', true); // True will log the string as well
Coming Soon
- A way to set command line arguments as required and some sort of type inforcer to some extent.
scf/simple-command-factory 适用场景与选型建议
scf/simple-command-factory 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 06 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「commands」 「scf」 「php-cmd」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 scf/simple-command-factory 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 scf/simple-command-factory 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 scf/simple-command-factory 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Collection of handy Laravel artisan commands that most projects needs
Additional artisan commands for Laravel
This Package provides some usefully console features like the attribute syntax for arguments and options, validation, auto ask and casting.
The Missing Laravel Artisan Commands
GHT D-Tools Bundle
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-06-13
