Skip to content

Commit

Permalink
update readme, update default screenshots image
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Aug 8, 2021
1 parent 8e39a95 commit 2b43156
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 29 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Latest Stable Version](http://img.shields.io/packagist/v/inhere/console.svg)](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)

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

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

Expand All @@ -20,7 +20,8 @@ Provide console parameter parsing, command run, color style output, user informa
> 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
- 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`)
Expand Down Expand Up @@ -82,11 +83,18 @@ phpunit
phpdbg -dauto_globals_jit=Off -qrr /usr/local/bin/phpunit --coverage-text
```

## Project use

Check out these projects, which use https://github.com/inhere/php-console :

- [kite](https://github.com/inhere/kite) Kite is a tool for help development.
- More, please see [github used by](https://github.com/inhere/php-console/network/dependents?package_id=UGFja2FnZS01NDI5NzMxOTI%3D)

## License

[MIT](LICENSE)

## My other projects
## My projects

- [inhere/php-validate](https://github.com/inhere/php-validate) A compact and full-featured php verification library
- [inhere/sroute](https://github.com/inhere/php-srouter) Lightweight and fast HTTP request routing library
7 changes: 7 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ phpunit
phpdbg -dauto_globals_jit=Off -qrr /usr/local/bin/phpunit --coverage-text
```

## 使用console的项目

看看这些使用了 https://github.com/inhere/php-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)

## License

[MIT](LICENSE)
Expand Down
Binary file modified docs/screenshots/app-command-list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/Command/CorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CorCommand extends Command
*/
public static function aliases(): array
{
return ['coro'];
return ['co', 'coro'];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion examples/Command/DemoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DemoCommand extends Command
{
protected static $name = 'demo';

protected static $description = 'this is a demo alone command. but config use configure(), like symfony console: argument define by position';
protected static $description = 'this is a demo alone command. but use Definition instead of annotations';

/**
* {@inheritDoc}
Expand Down
5 changes: 3 additions & 2 deletions examples/app
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ require dirname(__DIR__) . '/test/boot.php';

// create app instance
$app = new Application([
'debug' => true,
'rootPath' => dirname(__DIR__),
'debug' => true,
'rootPath' => dirname(__DIR__),
'description' => 'This is demo console application',
]);

$app->setLogo("
Expand Down
5 changes: 4 additions & 1 deletion src/Component/Formatter/HelpPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class HelpPanel extends MessageFormatter
* Show console help message
*
* There are config structure. you can setting some or ignore some. will only render it when value is not empty.
*
* ```
* [
* description string The description text. e.g 'Composer version 1.3.2'
* usage string The usage message text. e.g 'command [options] [arguments]'
Expand All @@ -73,6 +75,7 @@ class HelpPanel extends MessageFormatter
* ]
* examples array|string The command usage example. e.g 'php server.php {start|reload|restart|stop} [-d]'
* ]
* ```
*
* @param array $config The config data
*/
Expand Down Expand Up @@ -135,7 +138,7 @@ public static function show(array $config): void
if (is_string($value)) {
$value = trim($value);
$section = ucfirst($section);
$parts[] = "<comment>$section</comment>:\n {$value}\n";
$parts[] = "<comment>$section</comment>:\n $value\n";
}
}

Expand Down
56 changes: 35 additions & 21 deletions src/Concern/ApplicationHelpTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
*/
trait ApplicationHelpTrait
{
/**
* @var string|array
*/
protected $moreHelpInfo = '';

/***************************************************************************
* Show information for the application
***************************************************************************/
Expand All @@ -55,10 +60,11 @@ trait ApplicationHelpTrait
*/
public function showVersionInfo(): void
{
$os = PHP_OS;
$date = date('Y.m.d');
$logo = '';
$name = $this->getParam('name', 'Console Application');
$os = PHP_OS;
$date = date('Y.m.d');
$logo = '';
$name = $this->getParam('name', 'Console Application');

$version = $this->getParam('version', 'Unknown');
$publishAt = $this->getParam('publishAt', 'Unknown');
$updateAt = $this->getParam('updateAt', 'Unknown');
Expand Down Expand Up @@ -115,20 +121,19 @@ public function showHelpInfo(string $command = ''): void
$globalOptions['--gen-file'] = 'The output file for generate auto completion script';
}

$globalOptions = FormatUtil::alignOptions($globalOptions);

/** @var Output $out */
$out = $this->output;
$out->helpPanel([
$helpInfo = [
'Usage' => "$binName <info>{command}</info> [--opt -v -h ...] [arg0 arg1 arg2=value2 ...]",
'Options' => $globalOptions,
'Options' => FormatUtil::alignOptions($globalOptions),
'Example' => [
'- run a command/subcommand:',
"$binName test run a independent command",
"$binName home index run a sub-command of the group",
sprintf("$binName home%sindex run a sub-command of the group", $delimiter),
"$binName help {command} see a command help information",
"$binName home index -h see a sub-command help of the group",
sprintf("$binName home%sindex -h see a sub-command help of the group", $delimiter),
"$binName home index run a subcommand of the group",
sprintf("$binName home%sindex run a subcommand of the group", $delimiter),
'',
'- display help for command:',
"$binName help COMMAND see a command help information",
"$binName home index -h see a subcommand help of the group",
sprintf("$binName home%sindex -h see a subcommand help of the group", $delimiter),
],
'Help' => [
'Generate shell auto completion scripts:',
Expand All @@ -138,7 +143,16 @@ public function showHelpInfo(string $command = ''): void
" $binName --auto-completion --shell-env zsh --gen-file stdout",
" $binName --auto-completion --shell-env bash --gen-file myapp.sh",
],
]);
];

// custom more help info
if ($this->moreHelpInfo) {
$helpInfo['More Information'] = $this->moreHelpInfo;
}

/** @var Output $out */
$out = $this->output;
$out->helpPanel($helpInfo);
}

/**
Expand Down Expand Up @@ -224,7 +238,7 @@ public function showCommandList(): void
}

$aliases = $options['aliases'];
$extra = $aliases ? ColorTag::wrap(' [alias: ' . implode(',', $aliases) . ']', 'info') : '';
$extra = $aliases ? ColorTag::wrap(' (alias: ' . implode(',', $aliases) . ')', 'info') : '';

$commandArr[$name] = $desc . $extra;
}
Expand Down Expand Up @@ -265,7 +279,7 @@ public function showCommandList(): void
]);

unset($groupArr, $commandArr, $internalCommands);
Console::write("More command information, please use: <cyan>$scriptName {command} -h</cyan>");
Console::write("More command information, please use: <cyan>$scriptName COMMAND -h</cyan>");
Console::flushBuffer();
}

Expand All @@ -292,9 +306,9 @@ protected function dumpAutoCompletion(string $shellEnv, array $data): void
$router = $this->getRouter();

// info
$glue = ' ';
$genFile = $input->getStringOpt('gen-file', 'none');
$tplDir = dirname(__DIR__, 2) . '/resource/templates';
$glue = ' ';
$genFile = $input->getStringOpt('gen-file', 'none');
$tplDir = dirname(__DIR__, 2) . '/resource/templates';

if ($shellEnv === 'bash') {
$tplFile = $tplDir . '/bash-completion.tpl';
Expand Down

0 comments on commit 2b43156

Please sign in to comment.