bear8421/command-line-tool

Base Command Line Tool use Silly CLI micro-framework based on Symfony Console

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

This package is auto-updated.

Last update: 2024-10-21 20:46:47 UTC


README

Latest Stable Version Total Downloads License PHP Version Require

Start Project Command Line Tool use PHP with Silly CLI micro-framework based on Symfony Console

Donate Me

Buy me a coffee: https://paypal.me/nguyenanhung

Summary

Install the Application

Run this command from the directory in which you want to install your new CLI micro-framework application.

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

or

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

Replace [my-app-name] with the desired directory name for your new application.

Usage

Create TestCommand in namespace Bear\App\Command

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);
    }
}

And declare Command in Bear in bear file in root folder

#!/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();
}

Running the application is the same as running any other Symfony Console application:

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

Silly\Application extends Symfony\Console\Application and can be used wherever Symfony's Application can.

Binaries Bash Setup

Setup in to .bash_profile or .zshrc

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

Reload Bash session

source ~/.bash_profile

hoặc

source ~/.zshrc

Use with Binaries

bear greet --upper vietnam

Documentation

Also see Official Document here: https://github.com/bear8421/command-line-tool/tree/main/docs

Contact

If any question & request, please contact following information

From Hanoi with Love ❤️