🖥 PHP CLI application library, provide console argument parse, console controller/command run, color style, user interactive, format information show and more. 功能全面的PHP命令行应用库。提供控制台参数解析, 命令运行,颜色风格输出, 用户信息交互, 特殊格式信息显示

Last update: May 25, 2022

PHP Console

License Php Version Latest Stable Version Github Actions Status

A simple, full-featured php command line application library.

Provide console parameter parsing, command run, color style output, user information interaction, and special format information display.

中文README

Command line preview

app-command-list

Features

Easy to use. Can be easily integrated into any existing project.

  • Command line application, controller, command parsing run on the command line
  • Support for setting aliases for commands. A command can have multiple aliases. Support command display/hide, enable/disable
  • Full-featured command line option parameter parsing (named parameters, short options -s, long options --long).
  • The input, output of the command line, management, use
  • Command method comments are automatically parsed as help information (by default, @usage @arguments @options @example)
  • Support for outputting message texts of multiple color styles (info, comment, success, warning, danger, error ... )
  • Commonly used special format information display (section, panel, padding, helpPanel, table, tree, title, list, multiList)
  • Rich dynamic information display (pending/loading, pointing, spinner, counterTxt, dynamicText, progressTxt, progressBar)
  • Common user information interaction support (select, multiSelect, confirm, ask/question, askPassword/askHiddenInput)
  • Support for predefined parameter definitions like symfony/console (giving parameter values by position, recommended when strict parameter restrictions are required)
  • The color output is windows linux mac compatible. Environments that do not support color will automatically remove the relevant CODE.
  • Quickly generate auto-completion scripts for the current application in the bash/zsh environment
  • NEW: Support start an interactive shell for run application

Built-in tools

  • Built-in Phar packaging tool class, which can be easily packaged into phar files. Easy to distribute and use
    • Run the command php examples/app phar:pack in the example, which will package this console library into an app.phar
  • Built-in file download tool class under command line with progress bar display
  • Command line php code highlighting support (from jakub-onderka/php-console-highlighter and making some adjustments)
  • Simple Terminal screen, cursor control operation class
  • Simple process operations using classes (fork, run, stop, wait ..., etc.)

All features, effects; can be run in the example code phps/app in examples/. Basically covers all the features and can be tested directly

Installation

composer require inhere/console

Document List

Please go to WIKI for detailed usage documentation

Project address

Unit test

phpunit
// output coverage without xdebug
phpdbg -dauto_globals_jit=Off -qrr /usr/local/bin/phpunit --coverage-text

License

MIT

My other projects

GitHub

https://github.com/inhere/php-console
Comments
  • 1. call 'onAppStop' service, if it is registered.

    https://github.com/inhere/php-console/blob/2.x/src/Base/AbstractApplication.php#L212

            // call 'onAppStop' service, if it is registered.
            $this->fire(self::ON_STOP_RUN, $this);
    

    这里的 onAppStop service 怎么使用呢?

    Reviewed by hs-llsong at 2019-08-06 09:42
  • 2. execute() 方法语法错误时会报Call to a member function handle() on null

    execute($input, $output)方法语法错误时会报Call to a member function handle() on null 原因是 prepareRun 里面setter$this->errorHandler没有调用到

    Fatal error: Uncaught Error: Call to a member function handle() on null in /home/tester/vendor/inhere/console/src/Base/AbstractApplication.php:298
    Stack trace:
    #0 [internal function]: Inhere\Console\Base\AbstractApplication->handleException(Object(ParseError))
    #1 {main}
      thrown in /home/tester/vendor/inhere/console/src/Base/AbstractApplication.php on line 298
    
    Fatal error: Uncaught Error: Call to a member function handle() on null in /home/tester/vendor/inhere/console/src/Base/AbstractApplication.php:298
    Stack trace:
    #0 /home/tester/vendor/inhere/console/src/Base/AbstractApplication.php(285): Inhere\Console\Base\AbstractApplication->handleException(Object(ErrorException))
    #1 /home/tester/vendor/inhere/console/src/Base/AbstractApplication.php(270): Inhere\Console\Base\AbstractApplication->handleError(1, 'Uncaught Error:...', '/home/sll/Proje...', 298)
    #2 [internal function]: Inhere\Console\Base\AbstractApplication->Inhere\Console\Base\{closure}()
    #3 {main}
      thrown in /home/tester/vendor/inhere/console/src/Base/AbstractApplication.php on line 298
    
    Reviewed by hs-llsong at 2019-03-29 03:45
  • 3. 如何自定义命令的help(非子命令的help)

    如图,希望能够自定义命令的help信息,包括usage和example信息,发现这些代码是在php-console/src/Traits/ApplicationHelpTrait.php里面写死的

            /** @var Output $out */
            $out = $this->output;
            $out->helpPanel([
                'usage'   => "$script <info>{command}</info> [--opt -v -h ...] [arg0 arg1 arg2=value2 ...]",
                'example' => [
                    "$script test (run a independent command)",
                    "$script home{$sep}index (run a command of the group)",
                    "$script help {command} (see a command help information)",
                    "$script home{$sep}index -h (see a command help of the group)",
                    "$script --auto-completion --shell-env [zsh|bash] [--gen-file stdout]",
                ]
            ]);
    

    是否有办法自定义这些输出

    1111

    Reviewed by liudhzhyym at 2020-04-28 10:30
  • 4. wrong type parameter was passed

    PHP Fatal error: Uncaught TypeError: Argument 3 passed to Inhere\Console\Utils\Show::table() must be of the type array, boolean given, called in ......

    Reviewed by chenqinghe at 2017-11-17 03:13
  • 5. 用mb_strwidth代替mb_strlen来测量字符串宽度,便于表格显示

    原本使用mb_strlen来测量字符串宽度,在中文环境不太准确,所以当改用mb_strwidth时,能够准确检测出显示时的宽度

    而填充时如果使用str_pad,则仍然会因为宽度测量不准确而不能准确填充,所以改为用拼接字符串的形式来填充,缺点是只能在字符串的首尾填充

    代码中新增的私有方法(padByWidth)就是用于此类填充,原本考虑加入到StringHelper类中,但考虑到它属于另一个仓库,所以直接加入到了当前类中,建议可以重新封装到合适的类中

    Reviewed by charlestide at 2020-09-18 09:28
  • 6. 为什么在静态调用输出对象的时候不支持type呢?

    show::info('111'); 的时候控制台会输出 [INFO] 1111

    是不是在参数中增加一个type

    看了下代码, 在魔术方法中 的type 直接获取了style

     $style = self::$blockMethods[$method];
     return self::block($msg, $style === 'primary' ? 'IMPORTANT' : $style, $style, $quit);
    

    目前项目中修改魔术方法中的参数获取,在使用静态调用的时候可以传递type, 想问下目前这样做的目的

    Reviewed by ghost at 2019-04-13 13:39
  • 7. chore(deps): bump actions/checkout from 2 to 3

    Bumps actions/checkout from 2 to 3.

    Release notes

    Sourced from actions/checkout's releases.

    v3.0.0

    • Update default runtime to node16

    v2.4.0

    • Convert SSH URLs like org-<ORG_ID>@github.com: to https://github.com/ - pr

    v2.3.5

    Update dependencies

    v2.3.4

    v2.3.3

    v2.3.2

    Add Third Party License Information to Dist Files

    v2.3.1

    Fix default branch resolution for .wiki and when using SSH

    v2.3.0

    Fallback to the default branch

    v2.2.0

    Fetch all history for all tags and branches when fetch-depth=0

    v2.1.1

    Changes to support GHES (here and here)

    v2.1.0

    Changelog

    Sourced from actions/checkout's changelog.

    Changelog

    v2.3.1

    v2.3.0

    v2.2.0

    v2.1.1

    • Changes to support GHES (here and here)

    v2.1.0

    v2.0.0

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    Reviewed by dependabot[bot] at 2022-03-02 11:22
  • 8. fix get version error

    fix error detail :

    [ERROR] An error occurred! MESSAGE: Argument 2 passed to Inhere\Console\Util\Show::aList() must be of the type string, null given, called in E:\Dev\Code\New\php-redis-cli\vendor\inhere\console\src\Traits\FormatOutputAwareTrait.php on line 150
    
    Reviewed by WangNingkai at 2019-11-09 14:40
  • 9. fixed:table opts error

    原来的代码只能修改showBorder,使用$output->table()这个的时候就不对了

    array(10) {
      ["showBorder"]=>
      array(2) {
        ["showBorder"]=>
        bool(true)
        ["columns"]=>
        array(3) {
          [0]=>
          string(2) "ID"
          [1]=>
          string(12) "时间"
          [2]=>
          string(6) "邮箱"
        }
      }
      ["leftIndent"]=>
      string(2) "  "
      ["titlePos"]=>
      string(1) "l"
      ["titleStyle"]=>
      string(4) "bold"
      ["headStyle"]=>
      string(7) "comment"
      ["headBorderChar"]=>
      string(1) "="
      ["bodyStyle"]=>
      string(0) ""
      ["rowBorderChar"]=>
      string(1) "-"
      ["colBorderChar"]=>
      string(1) "|"
      ["columns"]=>
      array(0) {
      }
    }
    
    Reviewed by sy-records at 2019-10-18 10:40
A PHP library for command-line argument processing

GetOpt.PHP GetOpt.PHP is a library for command-line argument processing. It supports PHP version 5.4 and above. Releases For an overview of the releas

May 24, 2022
A PHP library for command-line argument processing

GetOpt.PHP GetOpt.PHP is a library for command-line argument processing. It supports PHP version 7.1 and above. Releases For an overview of the releas

May 20, 2022
Another Command Line Argument Parser

Optparse — Another Command Line Argument Parser Install 1. Get composer. 2. Put this into your local composer.json: { "require": { "chh/optparse

Nov 1, 2019
Extendable Interactive Make Command for Laravel
Extendable Interactive Make Command for Laravel

Extendable Interactive Make Command for Laravel Make your life easier with interactive make command! Installation composer require hydreflab/laravel-m

Feb 12, 2022
Generic PHP command line flags parse library
Generic PHP command line flags parse library

PHP Flag Generic PHP command line flags parse library Features Generic CLI options and arguments parser. Support set value data type(int,string,bool,a

Mar 2, 2022
Console - The Console component eases the creation of beautiful and testable command line interfaces.

Console Component The Console component eases the creation of beautiful and testable command line interfaces. Sponsor The Console component for Symfon

May 25, 2022
A powerful command line application framework for PHP. It's an extensible, flexible component, You can build your command-based application in seconds!
A powerful command line application framework for PHP. It's an extensible, flexible component, You can build your command-based application in seconds!

CLIFramework CLIFramework is a command-line application framework, for building flexiable, simple command-line applications. Commands and Subcommands

May 17, 2022
An Interactive Shell to Lumen Framework.
An Interactive Shell to Lumen Framework.

ABANDONED Please consider to use the official Laravel Tinker, it is also compatible with Lumen: laravel/tinker Lumen Artisan Tinker An Interactive She

Apr 1, 2022
🤖 GitHub Action to run symfony console commands.

Symfony Console GitHub Action Usage You can use it as a Github Action like this: # .github/workflows/lint.yml name: "Lint" on: pull_request: push

Feb 5, 2022
Simple command-line tool to access HiWeb account information

Simple command-line tool to access HiWeb account information.

Nov 17, 2021
☄️ PHP CLI mode development framework, supports Swoole, WorkerMan, FPM, CLI-Server
☄️  PHP CLI mode development framework, supports Swoole, WorkerMan, FPM, CLI-Server

☄️ PHP CLI mode development framework, supports Swoole, WorkerMan, FPM, CLI-Server / PHP 命令行模式开发框架,支持 Swoole、WorkerMan、FPM、CLI-Server

May 26, 2022
WP-CLI Trait Package Command

WP-CLI Trait Package Command Generate plugin or php model files e.g. post-type or taxonomy for WP-Trait Package in Develop WordPress Plugin. Installat

Dec 17, 2021
Sylius plugin to define a command cli context (ChannelContext)
Sylius plugin to define a command cli context (ChannelContext)

Cli Context Plugin This plugin provide a default channel context for your Symfony Command. When Sylius load a resource implements Sylius\Component\Res

Feb 21, 2022
The Platform.sh CLI is the official command-line interface for Platform.sh

The Platform.sh CLI is the official command-line interface for Platform.sh. Use this tool to interact with your Platform.sh projects, and to build them locally for development purposes.

May 17, 2022
Image Optimize Command - Easily optimize images using WP CLI

Image Optimize Command is a WP CLI wrapper for spatie/image-optimizer which optimize gif, jpeg, jpg, png, svg, webp images by running them through a chain of various image optimization tools.

Apr 28, 2022
An Elegant CLI Library for PHP

Commando An Elegant PHP CLI Library Commando is a PHP command line interface library that beautifies and simplifies writing PHP scripts intended for c

May 12, 2022
Library for creating CLI commands or applications

Console Motivation: this library purpose is to provide a lighter and more robust API for console commands and/or applications to symfony/console. It c

Oct 20, 2021
Skeleton for creating a new Command Line Interface application with a minimum of dependencies.

Skeleton for creating a new Command Line Interface application with a minimum of dependencies.

Jan 17, 2022
The Hoa\Console library.
The Hoa\Console library.

Hoa is a modular, extensible and structured set of PHP libraries. Moreover, Hoa aims at being a bridge between industrial and research worlds. Hoa\Con

May 20, 2022