2017 © Pedro Peláez
 

library cli-utils

some cli tool library of the php

image

toolkit/cli-utils

some cli tool library of the php

  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 2050 % Grown

The README.md

CLI Utils

License Php Version Latest Stable Version Github Actions Status, (*1)

Provide some useful utils for the php CLI application., (*2)

  • Simple CLI arguments and options parser.
  • Terminal console color render
  • CLI code highlighter
  • Build simple CLI application
  • CLI ENV information helper

Install

  • Required PHP 8.0+
composer require toolkit/cli-utils

Console color

Color::printf('<info>%s</info> world', 'hello');
Color::println('hello world', 'info');
Color::println('hello world', 'error');
Color::println('hello world', 'warning');
Color::println('hello world', 'success');

echo Color::render('hello world', 'success');

colors, (*3)

Console log

use Toolkit\Cli\Util\Clog;

// run: php example/log.php
foreach (Clog::getLevelNames() as $level) {
    Clog::log($level, "example log $level message");
}

clog-example, (*4)

Simple console app

use Toolkit\Cli\CliApp;

// run:
// php example/mycmd
// php example/mycmd -i abc --lon def ag1 ag2 ag3
$cmd = CliApp::new('cmd1', 'this is my cli application');
$cmd->addOpt('info', 'i', 'Output some information');
$cmd->addOpt('long-option-name', 'lon', 'this is a long option for command');
$cmd->addArg('arg1', 'this is first argument');

$cmd->setHandler(function (CliApp $cmd) {
  var_dump($cmd->getOpts(), $cmd->getArgs(), $cmd->getRemainArgs());
});

$cmd->run();

clog-example, (*5)

Terminal control

examples:, (*6)

use Toolkit\Cli\Util\Terminal;

Terminal::forward(3);
Terminal::backward(2);

Terminal::clearLine();

Terminal::clearScreen();

Control Methods

/**
 * @method static showCursor()
 * @method static hideCursor()
 * @method static savePosition()
 * @method static restorePosition()
 * @method static toTop()
 * @method static toColumn(int $step)
 * @method static up(int $step = 1)
 * @method static down(int $step = 1)
 * @method static forward(int $step = 1)
 * @method static backward(int $step = 1) Moves the terminal cursor backward
 * @method static toPrevNLineStart(int $step = 1)
 * @method static toNextNLineStart(int $step = 1)
 * @method static coordinate(int $col, int $row = 0)
 * @method static clearScreen()
 * @method static clearLine()
 * @method static clearToScreenBegin()
 * @method static clearToScreenEnd()
 * @method static scrollUp(int $step = 1)
 * @method static scrollDown(int $step = 1)
 * @method static showSecondaryScreen()
 * @method static showPrimaryScreen()
 */

PHP file highlight

This is inspire jakub-onderka/php-console-highlighter, (*7)

use Toolkit\Cli\Util\Highlighter;

// this is an comment
$rendered = Highlighter::create()->highlight(file_get_contents(__FILE__));

\Toolkit\Cli\Cli::write($rendered);

colors, (*8)

CLI downloader

use Toolkit\Cli\Download;

$url  = 'http://no2.php.net/distributions/php-7.2.5.tar.bz2';
$down = Download::file($url, '');

// $down->setShowType('bar');
// $down->setDebug(true);
$down->start();

Progress bar, (*9)

down-file-bar, (*10)

Progress text, (*11)

down-file-txt-bar, (*12)

Projects

  • https://github.com/inhere/php-console Build rich console application
  • https://github.com/php-toolkit/pflag Generic flags parse library, build simple console application.

Refer

  • https://www.sitepoint.com/howd-they-do-it-phpsnake-detecting-keypresses/

License

MIT, (*13)

The Versions

07/05 2018

dev-master

9999999-dev https://github.com/php-toolkit/cli-utils

some cli tool library of the php

  Sources   Download

MIT

The Requires

  • php >7.0.0

 

php library tool

07/05 2018

v1.0.1

1.0.1.0 https://github.com/php-toolkit/cli-utils

some cli tool library of the php

  Sources   Download

MIT

The Requires

  • php >7.0.0

 

php library tool

07/05 2018

v1.0.0

1.0.0.0 https://github.com/php-toolkit/cli-utils

some cli tool library of the php

  Sources   Download

MIT

The Requires

  • php >7.0.0

 

php library tool