PHP code example of bear8421 / command-line-tool

1. Go to this page and download the library: Download bear8421/command-line-tool library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bear8421 / command-line-tool example snippets


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


#!/usr/bin/env php


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

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

// Includes Composer Vendor Packages
greet', [
		'u|upper',
		'r|randomFaker'
]), TestCommand::class)->descriptions(TestCommand::$desc, TestCommand::$optionsInfo);

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


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