bear8421/command-line-tool

基于 Symfony Console 的 Silly CLI 微框架的基命令行工具

v1.1.9 2024-09-21 20:31 UTC

This package is auto-updated.

Last update: 2024-09-21 20:38:40 UTC


README

Latest Stable Version Total Downloads License PHP Version Require

开始项目使用 PHP 和基于 Symfony Console 的 Silly CLI 微框架构建命令行工具

捐赠我

买我一杯咖啡:https://paypal.me/nguyenanhung

摘要

安装应用程序

从您想安装新 CLI 微框架应用程序的目录运行此命令。

composer create-project bear8421/command-line-tool [my-app-name]

php composer.phar create-project bear8421/command-line-tool [my-app-name]

[my-app-name] 替换为您新应用程序希望使用的目录名称。

用法

在命名空间 Bear\App\Command 中创建 TestCommand

class TestCommand
{
    public function __invoke($name, $upper, OutputInterface $output)
    {
        if ($name) {
            $text = 'Hello, Iam ' . $name;
            $output->writeln("Bear");
        } else {
            $text = 'Hello, Iam. BEAR';
        }
        if ($upper) {
            $text = strtoupper($text);
        }
        $output->writeln($text);
    }
}

并在根目录中的 bear 文件中声明 Bear

#!/usr/bin/env php
<?php

if (php_sapi_name() !== 'cli') {
	exit;
}

// Register Application Space
define('BEAR', $_SERVER['BEAR_ENV'] ?? 'production');

// Includes Composer Vendor Packages
require_once __DIR__ . '/vendor/autoload.php';

use Silly\Edition\PhpDi\Application;
use Bear\App\Command\TestCommand;

$app = new Application();
$app->setName(ENV_APP_NAME);

// Routes list Command
$app->command(parseExpressionOptions('greet', [
		'u|upper',
		'r|randomFaker'
]), TestCommand::class)->descriptions(TestCommand::$desc, TestCommand::$optionsInfo);

try {
    $app->run();
}
catch (Exception $e) {
    echo $e->getMessage();
}

运行应用程序与运行任何其他 Symfony Console 应用程序相同

$ php bear greet
Hello
$ php bear greet vietnam --upper
HELLO JOHN
$ php bear greet --upper vietnam
HELLO JOHN

Silly\Application 扩展 Symfony\Console\Application 并可以在任何需要 Symfony 的 Application 的地方使用。

Bash 设置二进制文件

设置到 .bash_profile.zshrc

export PATH="/your/path/bin:$PATH"

重新加载 Bash 会话

source ~/.bash_profile

或者

source ~/.zshrc

使用二进制文件

bear greet --upper vietnam

文档

还可以在此处查看官方文档: https://github.com/bear8421/command-line-tool/tree/main/docs

联系

如有任何问题 & 请求,请联系以下信息

从河内,带着爱 ❤️