Skip to content

Commit 5d46a87

Browse files
authored
Merge pull request #20 from inhere/master
2 parents 6b5096b + ffa2ea1 commit 5d46a87

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1612
-1132
lines changed

Diff for: .github/workflows/php.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Unit-tests
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.php'
7+
- 'composer.json'
8+
- '**.yml'
9+
10+
jobs:
11+
test:
12+
name: Test on php ${{ matrix.php}} and ${{ matrix.os }}
13+
runs-on: ${{ matrix.os }}
14+
timeout-minutes: 10
15+
strategy:
16+
fail-fast: true
17+
matrix:
18+
php: [7.3, 7.4] #
19+
os: [ubuntu-latest, macOS-latest] # windows-latest,
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v2
24+
25+
- name: Set ENV vars
26+
# https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
27+
run: |
28+
echo "RELEASE_TAG=${GITHUB_REF:10}" >> $GITHUB_ENV
29+
echo "RELEASE_NAME=$GITHUB_WORKFLOW" >> $GITHUB_ENV
30+
31+
- name: Display Env
32+
run: env
33+
34+
# usage refer https://github.com/shivammathur/setup-php
35+
- name: Setup PHP
36+
timeout-minutes: 5
37+
uses: shivammathur/setup-php@v2
38+
with:
39+
php-version: ${{ matrix.php}}
40+
tools: pecl, php-cs-fixer, phpunit
41+
extensions: mbstring, dom, fileinfo, mysql, openssl, igbinary, redis # , swoole-4.4.19 #optional, setup extensions
42+
ini-values: post_max_size=56M, short_open_tag=On #optional, setup php.ini configuration
43+
coverage: none #optional, setup coverage driver: xdebug, none
44+
45+
- name: Install dependencies
46+
run: composer install --no-progress --no-suggest
47+
48+
# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
49+
# Docs: https://getcomposer.org/doc/articles/scripts.md
50+
51+
- name: Run unit tests
52+
run: php vendor/bin/phpunit

Diff for: .github/workflows/release.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Tag-release
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
jobs:
9+
release:
10+
name: Test on php ${{ matrix.php}}
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 10
13+
strategy:
14+
fail-fast: true
15+
matrix:
16+
php: [7.3]
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v2
21+
22+
- name: Set ENV for github-release
23+
# https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
24+
run: |
25+
echo "RELEASE_TAG=${GITHUB_REF:10}" >> $GITHUB_ENV
26+
echo "RELEASE_NAME=$GITHUB_WORKFLOW" >> $GITHUB_ENV
27+
28+
# usage refer https://github.com/shivammathur/setup-php
29+
- name: Setup PHP
30+
timeout-minutes: 5
31+
uses: shivammathur/setup-php@v2
32+
with:
33+
php-version: ${{ matrix.php}}
34+
tools: pecl, php-cs-fixer, phpunit
35+
extensions: mbstring, dom, fileinfo, mysql, openssl # , swoole-4.4.19 #optional, setup extensions
36+
ini-values: post_max_size=56M, short_open_tag=On #optional, setup php.ini configuration
37+
coverage: none #optional, setup coverage driver: xdebug, none
38+
39+
- name: Install dependencies # eg: v1.0.3
40+
run: |
41+
tag1=${GITHUB_REF#refs/*/}
42+
echo "release tag: ${tag1}"
43+
composer install --no-progress --no-suggest
44+
45+
# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
46+
# Docs: https://getcomposer.org/doc/articles/scripts.md
47+
48+
# - name: Build phar and send to github assets
49+
# run: |
50+
# echo $RELEASE_TAG
51+
# echo $RELEASE_NAME
52+
# php -d phar.readonly=0 bin/kite phar:pack -o kite-${RELEASE_TAG}.phar --no-progress
53+
# php kite-${RELEASE_TAG}.phar -V
54+
55+
# https://github.com/actions/create-release
56+
- uses: meeDamian/[email protected]
57+
with:
58+
gzip: false
59+
token: ${{ secrets.GITHUB_TOKEN }}
60+
tag: ${{ env.RELEASE_TAG }}
61+
name: ${{ env.RELEASE_TAG }}
62+
# files: kite-${{ env.RELEASE_TAG }}.phar

Diff for: .travis.yml

-21
This file was deleted.

Diff for: CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
## v4.0.x
4+
5+
> begin at: 2020.08.21
6+
7+
38
## v3.0.x
49

510
> publish at: 2019.01.03

Diff for: README.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
# PHP console
1+
# PHP Console
22

33
[![License](https://img.shields.io/packagist/l/inhere/console.svg?style=flat-square)](LICENSE)
4-
[![Php Version](https://img.shields.io/badge/php-%3E=7.1.0-brightgreen.svg?maxAge=2592000)](https://packagist.org/packages/inhere/console)
4+
[![Php Version](https://img.shields.io/badge/php-%3E=7.2.0-brightgreen.svg?maxAge=2592000)](https://packagist.org/packages/inhere/console)
55
[![Latest Stable Version](http://img.shields.io/packagist/v/inhere/console.svg)](https://packagist.org/packages/inhere/console)
6+
[![Github Actions Status](https://github.com/inhere/php-console/workflows/Unit-tests/badge.svg)](https://github.com/inhere/php-console/actions)
67

78
A simple, full-featured php command line application library.
9+
810
Provide console parameter parsing, command run, color style output, user information interaction, and special format information display.
911

10-
> **[中文README](./README_cn.md)**
12+
> **[中文README](./README.zh-CN.md)**
1113
1214
## Command line preview
1315

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

3236
### Built-in tools
3337

@@ -40,7 +44,7 @@ Provide console parameter parsing, command run, color style output, user informa
4044

4145
> All features, effects; can be run in the example code `phps/app` in `examples/`. Basically covers all the features and can be tested directly
4246
43-
## Quick installation
47+
## Installation
4448

4549
```bash
4650
composer require inhere/console

Diff for: README_cn.md renamed to README.zh-CN.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
# php 命令行应用库
1+
# PHP Console
22

33
[![License](https://img.shields.io/packagist/l/inhere/console.svg?style=flat-square)](LICENSE)
4-
[![Php Version](https://img.shields.io/badge/php-%3E=7.1.0-brightgreen.svg?maxAge=2592000)](https://packagist.org/packages/inhere/console)
4+
[![Php Version](https://img.shields.io/badge/php-%3E=7.2.0-brightgreen.svg?maxAge=2592000)](https://packagist.org/packages/inhere/console)
55
[![Latest Stable Version](http://img.shields.io/packagist/v/inhere/console.svg)](https://packagist.org/packages/inhere/console)
6+
[![Github Actions Status](https://github.com/inhere/php-console/workflows/Unit-tests/badge.svg)](https://github.com/inhere/php-console/actions)
67

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

@@ -18,7 +19,8 @@
1819
1920
- 命令行应用, 命令行的 `controller`, `command` 解析运行
2021
- 支持给命令设置别名,一个命令可以有多个别名。支持命令的显示/隐藏,启用/禁用
21-
- 功能全面的命令行的选项参数解析(命名参数,短选项,长选项 ...)。命令行的 `input`, `output` 管理、使用
22+
- 功能全面的命令行的选项参数解析(命名参数,短选项 `-s`,长选项 `--long`)
23+
- 命令行下的 输入`input`, 输出 `output` 管理、使用
2224
- 命令方法注释自动解析为帮助信息(默认提取 `@usage` `@arguments` `@options` `@example` 等信息)
2325
- 支持输出多种颜色风格的消息文本(`info`, `comment`, `success`, `warning`, `danger`, `error` ... )
2426
- 常用的特殊格式信息显示(`section`, `panel`, `padding`, `helpPanel`, `table`, `tree`, `title`, `list`, `multiList`)

Diff for: TODO.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# TODO
2+
3+
- [x] Add more events supports
4+
- [ ] Add nested command supports
5+
- [ ] Simpler bash command completion support

Diff for: composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
}
2323
],
2424
"require": {
25-
"php": ">7.1.0",
25+
"php": ">7.2.0",
2626
"toolkit/cli-utils": "~1.0",
2727
"toolkit/stdlib": "~1.0",
2828
"toolkit/sys-utils": "~1.0"
2929
},
3030
"require-dev": {
31-
"phpunit/phpunit": "^7.5"
31+
"phpunit/phpunit": "~9.1"
3232
},
3333
"autoload": {
3434
"psr-4": {

Diff for: docs/screenshots/alone-command-help.jpg

78.9 KB
Loading

Diff for: examples/Controller/HomeController.php

+30-15
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
/**
2020
* default command controller. there are some command usage examples(1)
2121
* Class HomeController
22+
*
2223
* @package Inhere\Console\Examples\Controller
2324
*/
2425
class HomeController extends Controller
@@ -34,14 +35,15 @@ protected static function commandAliases(): array
3435
{
3536
return [
3637
// now, 'home:i' is equals to 'home:index'
37-
'i' => 'index',
38-
'prg' => 'progress',
39-
'pgb' => 'progressBar',
40-
'l' => 'list',
41-
'af' => 'artFont',
42-
'ml' => 'multiList',
43-
'sl' => 'splitLine',
44-
'dt' => 'dynamicText',
38+
'i' => 'index',
39+
'prg' => 'progress',
40+
'pgb' => 'progressBar',
41+
'l' => 'list',
42+
'af' => 'artFont',
43+
'ml' => 'multiList',
44+
'sl' => 'splitLine',
45+
'dt' => 'dynamicText',
46+
'defArg' => ['da', 'defarg'],
4547
];
4648
}
4749

@@ -50,6 +52,10 @@ protected function init(): void
5052
parent::init();
5153

5254
$this->addCommentsVar('internalFonts', implode(',', ArtFont::getInternalFonts()));
55+
56+
$this->setCommandMeta('defArg', [
57+
'desc' => 'the command args and opts config use defined configure, it like symfony console, please see defArgConfigure()',
58+
]);
5359
}
5460

5561
/**
@@ -75,6 +81,7 @@ protected function afterExecute(): void
7581
/**
7682
* this is a command's description message
7783
* the second line text
84+
*
7885
* @usage {command} [arg ...] [--opt ...]
7986
* @arguments
8087
* arg1 argument description 1
@@ -102,27 +109,27 @@ public function disabledCommand(): void
102109

103110
/**
104111
* command `defArgCommand` config
112+
*
105113
* @throws LogicException
106114
*/
107115
protected function defArgConfigure(): void
108116
{
109117
$this->createDefinition()
110-
->setDescription('the command arg/opt config use defined configure, it like symfony console: argument define by position')
118+
// ->setDescription('the command args and opts config use defined configure, it like symfony console, please see defArgConfigure()')
111119
->addArgument('name', Input::ARG_REQUIRED, "description for the argument 'name'")
112120
->addOption('yes', 'y', Input::OPT_BOOLEAN, "description for the option 'yes'")
113121
->addOption('opt1', null, Input::OPT_REQUIRED, "description for the option 'opt1'");
114122
}
115123

116-
/**
117-
* the command arg/opt config use defined configure, it like symfony console: argument define by position
118-
*/
124+
// desc set at $this->commandMetas.
119125
public function defArgCommand(): void
120126
{
121127
$this->output->dump($this->input->getArgs(), $this->input->getOpts(), $this->input->getBoolOpt('y'));
122128
}
123129

124130
/**
125131
* a command for test throw exception
132+
*
126133
* @throws RuntimeException
127134
*/
128135
public function exCommand(): void
@@ -177,6 +184,7 @@ public function colorCheckCommand(): void
177184

178185
/**
179186
* output art font text
187+
*
180188
* @options
181189
* --font Set the art font name(allow: {internalFonts}).
182190
* --italic Set the art font type is italic.
@@ -201,9 +209,10 @@ public function artFontCommand(): int
201209

202210
/**
203211
* dynamic notice message show: counterTxt. It is like progress txt, but no max value.
212+
*
213+
* @return int
204214
* @example
205215
* {script} {command}
206-
* @return int
207216
*/
208217
public function counterCommand(): int
209218
{
@@ -289,16 +298,19 @@ public function dynamicTextCommand(): void
289298

290299
/**
291300
* a progress bar example show, by Show::progressBar()
301+
*
292302
* @options
293303
* --type the progress type, allow: bar,txt. <cyan>txt</cyan>
294304
* --done-char the done show char. <info>=</info>
295305
* --wait-char the waiting show char. <info>-</info>
296306
* --sign-char the sign char show. <info>></info>
307+
*
308+
* @param Input $input
309+
*
310+
* @return int
297311
* @example
298312
* {script} {command}
299313
* {script} {command} --done-char '#' --wait-char ' '
300-
* @param Input $input
301-
* @return int
302314
*/
303315
public function progressCommand($input): int
304316
{
@@ -329,6 +341,7 @@ public function progressCommand($input): int
329341

330342
/**
331343
* a progress bar example show, by class ProgressBar
344+
*
332345
* @throws LogicException
333346
*/
334347
public function progressBarCommand(): void
@@ -470,6 +483,7 @@ public function paddingCommand(): void
470483

471484
/**
472485
* a example for use arguments on command
486+
*
473487
* @usage home:useArg [arg1=val1 arg2=arg2] [options]
474488
* @example
475489
* home:useArg status=2 name=john arg0 -s=test --page=23 -d -rf --debug --test=false -a v1 --ab -c -g --cd val -h '' -i stat=online
@@ -509,6 +523,7 @@ public function envCommand(): void
509523
/**
510524
* This is a demo for download a file to local
511525
* @usage {command} url=url saveTo=[saveAs] type=[bar|text]
526+
*
512527
* @example {command} url=https://github.com/inhere/php-console/archive/master.zip type=bar
513528
*/
514529
public function downCommand(): int

0 commit comments

Comments
 (0)