PHPackages                             inhere/console - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. inhere/console

ActiveLibrary[CLI &amp; Console](/categories/cli)

inhere/console
==============

php console library, provide console argument parse, console controller/command run, color style, user interactive, information show.

v4.1.7(1y ago)3477.4k↓25%48[1 issues](https://github.com/inhere/php-console/issues)12MITPHPPHP &gt;8.1CI passing

Since May 11Pushed 5mo ago15 watchersCompare

[ Source](https://github.com/inhere/php-console)[ Packagist](https://packagist.org/packages/inhere/console)[ Docs](https://github.com/inhere/php-console)[ RSS](/packages/inhere-console/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (82)Used By (12)

PHP Console
===========

[](#php-console)

[![License](https://camo.githubusercontent.com/b6a4221c4c4819099af6ed5d86b07b6f246b6564c8a53ea6e3a5adba50108a8d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f696e686572652f636f6e736f6c652e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Php Version](https://camo.githubusercontent.com/35d7daf4bbf1ee3024222a8f477cf45c25084f8429fba26d1a977a6ef2299fba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f696e686572652f636f6e736f6c653f6d61784167653d32353932303030)](https://packagist.org/packages/inhere/console)[![Latest Stable Version](https://camo.githubusercontent.com/db6be1f887f47969d28cb2804627292f50bfbbdd624f61e7be6272b744767b36/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e686572652f636f6e736f6c652e737667)](https://packagist.org/packages/inhere/console)[![Github Actions Status](https://github.com/inhere/php-console/workflows/Unit-tests/badge.svg)](https://github.com/inhere/php-console/actions)[![English](https://camo.githubusercontent.com/ed07c6ca77f8bef98ffb34dc57b13a2fe696ef80ad89c0630268726a72c12b26/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f526561646d652d456e676c6973682d627269676874677265656e2e7376673f6d61784167653d32353932303030)](README.en.md)

简洁、功能全面的php命令行应用库。提供控制台参数解析, 命令运行，颜色风格输出, 用户信息交互, 特殊格式信息显示。

> NOTICE: Current version **v4.1+**, require **PHP 8.0+**

命令行预览
-----

[](#命令行预览)

[![app-command-list](https://raw.githubusercontent.com/inhere/php-console/3.x/docs/screenshots/app-command-list.png)](https://raw.githubusercontent.com/inhere/php-console/3.x/docs/screenshots/app-command-list.png)

功能概览
----

[](#功能概览)

> 使用方便简单。可以方便的整合到任何已有项目中。

- 命令行应用, 命令行的 `controller`, `command` 解析运行
- 支持给命令设置别名,一个命令可以有多个别名。
    - 支持命令的显示/隐藏，启用/禁用
- 命令行下的 输入`input`, 输出 `output`， Flag解析管理、使用
- 功能全面的命令行的选项、参数解析
    - 命名参数，数组参数
    - 选项绑定 短选项 `-s`，长选项 `--long`
    - **NEW** v4 支持定义数据类型(`bool,int,string,array`)，解析后会自动格式化输入值
- 命令方法注释自动解析为帮助信息
    - 默认提取 `@usage` `@arguments` `@options` `@example` 等信息
    - **NEW** v4 版本支持从注释定义选项参数的数据类型
- 支持注册事件监听，错误处理等

### 更多特性

[](#更多特性)

- 支持输出多种颜色风格的消息文本(`info`, `comment`, `success`, `warning`, `danger`, `error` ... )
- 常用的特殊格式信息显示(`section`, `panel`, `padding`, `helpPanel`, `table`, `tree`, `title`, `list`, `multiList`)
- 丰富的动态信息显示(`pending/loading`, `pointing`, `spinner`, `counterTxt`, `dynamicText`, `progressTxt`, `progressBar`)
- 常用的用户信息交互支持(`select`, `multiSelect`, `confirm`, `ask/question`, `askPassword/askHiddenInput`)
- 支持类似 `symfony/console` 的预定义参数定义(按位置赋予参数值, 需要严格限制参数选项时推荐使用)
- 颜色输出是 `windows` `linux` `mac` 兼容的，不支持颜色的环境会自动去除相关CODE
- 快速的为当前应用生成 `bash/zsh` 环境下的自动补全脚本

### 内置工具

[](#内置工具)

- 内置Phar打包工具类，可以方便的将应用打包成`phar`文件。方便分发和使用
    - 运行示例中的命令 `php examples/app phar:pack`,会将此console库打包成一个`app.phar`
- 内置了命令行下的文件下载工具类，带有进度条显示
- 命令行的php代码高亮支持（来自于`jakub-onderka/php-console-highlighter`并做了一些调整）
- 简单的Terminal屏幕、光标控制操作类
- 简单的进程操作使用类（fork,run,stop,wait ... 等）

所有的特性，功能：

都可以运行 `examples/` 中的示例代码 `php examples/app` 展示出来的。基本上涵盖了所有功能，可以直接测试运行

项目地址
----

[](#项目地址)

- **github**
- **gitee**

快速安装
----

[](#快速安装)

- Requirement PHP 8.0+

```
composer require inhere/console
```

快速开始
----

[](#快速开始)

```
// file: examples/app
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;

$meta = [
    'name'    => 'My Console App',
    'version' => '1.0.2',
];

// 通常无需传入 $input $output ，会自动创建
// $app = new \Inhere\Console\Application($meta, $input, $output);
$app = new \Inhere\Console\Application($meta);

// 注册命令
$app->command(DemoCommand::class);
// 注册命令组
$app->addGroup(MyController::class);
// ... ...

// run
$app->run();
```

运行示例应用： `php examples/app`

文档列表
----

[](#文档列表)

**[从v3升级到v4](https://github.com/inhere/php-console/wiki/v3-upgrade-to-v4)**

- **[文档首页](https://github.com/inhere/php-console/wiki/home)**
- **[功能概览](https://github.com/inhere/php-console/wiki/overview)**
- **[安装](https://github.com/inhere/php-console/wiki/install)**
- **[创建应用](https://github.com/inhere/php-console/wiki/quick-start)**
- **[创建命令/组](https://github.com/inhere/php-console/wiki/create-command-and-group)**
- **[注册命令](https://github.com/inhere/php-console/wiki/register-command)**
- **[错误/异常捕获](https://github.com/inhere/php-console/wiki/error-handle)**

更多使用文档请点击跳转到[WIKI](https://github.com/inhere/php-console/wiki)查看

单元测试
----

[](#单元测试)

```
phpunit
// 没有xdebug时输出覆盖率
phpdbg -dauto_globals_jit=Off -qrr /usr/local/bin/phpunit --coverage-text
```

开发调试
----

[](#开发调试)

你可以通过环境变量 `CONSOLE_DEBUG=level`, 全局选项 `--debug level` 设置debug级别

```
# by ENV
$ CONSOLE_DEBUG=4 php examples/app
$ CONSOLE_DEBUG=5 php examples/app
# by global options
$ php examples/app --debug 4
```

使用console的项目
------------

[](#使用console的项目)

看看这些使用了  的项目:

- [kite](https://github.com/inhere/kite) PHP编写的，方便本地开发和使用的个人CLI工具应用
- More, please see [github used by](https://github.com/inhere/php-console/network/dependents?package_id=UGFja2FnZS01NDI5NzMxOTI%3D)

我的其他项目
------

[](#我的其他项目)

- [inhere/php-validate](https://github.com/inhere/php-validate) 一个简洁小巧且功能完善的php验证库
- [inhere/sroute](https://github.com/inhere/php-srouter) 轻量且快速的HTTP请求路由库

依赖包
---

[](#依赖包)

- [toolkit/cli-utils](https://github.com/php-toolkit/cli-utils)
- [toolkit/pflag](https://github.com/php-toolkit/pflag)
- [toolkit/stdlib](https://github.com/php-toolkit/stdlib)
- [toolkit/sys-utils](https://github.com/php-toolkit/sys-utils)

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

59

—

FairBetter than 99% of packages

Maintenance60

Regular maintenance activity

Popularity42

Moderate usage in the ecosystem

Community33

Small or concentrated contributor base

Maturity87

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 97.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~36 days

Recently: every ~280 days

Total

80

Last Release

394d ago

Major Versions

v1.2.1 → v2.2.52018-01-10

1.x-dev → v3.0.02019-01-01

v2.4.3 → v3.1.42019-10-18

v3.1.21 → v4.0.0beta12021-09-24

3.x-dev → v4.0.02021-10-14

PHP version history (8 changes)v0.5.1PHP &gt;=7.0.0

v1.2.1PHP &gt;=5.6.0

v2.4.1PHP &gt;7.0.0

v3.0.0PHP &gt;7.1.0

v3.1.14PHP &gt;7.3.0

v3.1.17PHP &gt;7.2.0

v4.1.0PHP &gt;8.0.1

v4.1.7PHP &gt;8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/d23e1decaf354e8f36a7ad61128865dc78dd63336c2d023d79aa3ff8ba2a05ff?d=identicon)[inhere](/maintainers/inhere)

---

Top Contributors

[![inhere](https://avatars.githubusercontent.com/u/5302062?v=4)](https://github.com/inhere "inhere (572 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![sy-records](https://avatars.githubusercontent.com/u/33931153?v=4)](https://github.com/sy-records "sy-records (2 commits)")[![WangNingkai](https://avatars.githubusercontent.com/u/23030927?v=4)](https://github.com/WangNingkai "WangNingkai (2 commits)")[![lihq1403](https://avatars.githubusercontent.com/u/25847339?v=4)](https://github.com/lihq1403 "lihq1403 (1 commits)")[![kduma](https://avatars.githubusercontent.com/u/1062582?v=4)](https://github.com/kduma "kduma (1 commits)")[![chenqinghe](https://avatars.githubusercontent.com/u/17957848?v=4)](https://github.com/chenqinghe "chenqinghe (1 commits)")[![nelsonsun](https://avatars.githubusercontent.com/u/26363174?v=4)](https://github.com/nelsonsun "nelsonsun (1 commits)")

---

Tags

clicli-flagscommand-lineconsoleconsole-applicationconsole-colorinteractivepharphp-consolecliconsolecommand-linepharcolorcommandconsole-applicationconsole-color

### Embed Badge

![Health badge](/badges/inhere-console/health.svg)

```
[![Health](https://phpackages.com/badges/inhere-console/health.svg)](https://phpackages.com/packages/inhere-console)
```

###  Alternatives

[symfony/console

Eases the creation of beautiful and testable command line interfaces

9.8k1.1B11.3k](/packages/symfony-console)[nunomaduro/collision

Cli error handling for console/command-line PHP applications.

4.6k331.8M8.5k](/packages/nunomaduro-collision)[nategood/commando

PHP CLI Commando Style

8123.3M38](/packages/nategood-commando)[kevinlebrun/colors.php

Colors for PHP CLI scripts

3426.7M45](/packages/kevinlebrun-colorsphp)[helhum/typo3-console

A reliable and powerful command line interface for TYPO3 CMS

2939.0M192](/packages/helhum-typo3-console)[nunomaduro/laravel-console-menu

Laravel Console Menu is an output method for your Laravel/Laravel Zero commands.

815412.0k48](/packages/nunomaduro-laravel-console-menu)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
