Skip to content

Commit fee4d91

Browse files
committed
some update, add new screenshots images
1 parent df3d174 commit fee4d91

File tree

14 files changed

+163
-24
lines changed

14 files changed

+163
-24
lines changed
155 KB
Loading

docs/screenshots/fmt-list.png

117 KB
Loading
110 KB
Loading

docs/screenshots/fmt-panel.png

73.1 KB
Loading

examples/Controllers/HomeController.php

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ protected static function commandAliases()
3030
// now, 'home:i' is equals to 'home:index'
3131
'i' => 'index',
3232
'prg' => 'progress',
33+
'pgb' => 'progressBar',
34+
'pwd' => 'password',
3335
'l' => 'list',
3436
'h' => 'helpPanel',
3537
'hp' => 'helpPanel',
3638
'af' => 'artFont',
39+
'ml' => 'multiList',
40+
'ms' => 'multiSelect',
3741
];
3842
}
3943

@@ -44,6 +48,11 @@ protected function init()
4448
$this->addAnnotationVar('internalFonts', implode(',', ArtFont::getInternalFonts()));
4549
}
4650

51+
protected function afterExecute()
52+
{
53+
$this->write('after command execute');
54+
}
55+
4756
/**
4857
* this is a command's description message
4958
* the second line text
@@ -203,7 +212,7 @@ public function progressCommand($input)
203212
'signChar' => $input->getOpt('sign-char', '>'),
204213
]);
205214
} else {
206-
$bar = $this->output->progressTxt($total, 'Doing gggg ...', 'Done');
215+
$bar = $this->output->progressTxt($total, 'Doing go g...', 'Done');
207216
}
208217

209218
$this->write('Progress:');
@@ -221,7 +230,7 @@ public function progressCommand($input)
221230
* a progress bar example show, by class ProgressBar
222231
* @throws \LogicException
223232
*/
224-
public function prgCommand()
233+
public function progressBarCommand()
225234
{
226235
$i = 0;
227236
$total = 120;
@@ -278,7 +287,7 @@ public function panelCommand()
278287
];
279288

280289
Show::panel($data, 'panel show', [
281-
'borderChar' => '#'
290+
'borderChar' => '*'
282291
]);
283292
}
284293

@@ -304,7 +313,7 @@ public function helpPanelCommand()
304313
}
305314

306315
/**
307-
* output format message: aList
316+
* output format message: list
308317
*/
309318
public function listCommand()
310319
{
@@ -327,6 +336,33 @@ public function listCommand()
327336
Show::aList($commands, 'a List show(Has key)');
328337
}
329338

339+
/**
340+
* output format message: multiList
341+
*/
342+
public function multiListCommand()
343+
{
344+
Show::multiList([
345+
'list0' => [
346+
'value in the list 0',
347+
'key' => 'value in the list 0',
348+
'key1' => 'value1 in the list 0',
349+
'key2' => 'value2 in the list 0',
350+
],
351+
'list1' => [
352+
'key' => 'value in the list 1',
353+
'key1' => 'value1 in the list 1',
354+
'key2' => 'value2 in the list 1',
355+
'value in the list 1',
356+
],
357+
'list2' => [
358+
'key' => 'value in the list 2',
359+
'value in the list 2',
360+
'key1' => 'value1 in the list 2',
361+
'key2' => 'value2 in the list 2',
362+
],
363+
]);
364+
}
365+
330366
/**
331367
* output format message: table
332368
*/
@@ -499,7 +535,7 @@ public function selectCommand()
499535
/**
500536
* This is a demo for use <magenta>Interact::multiSelect()</magenta> method
501537
*/
502-
public function msCommand()
538+
public function multiSelectCommand()
503539
{
504540
$opts = ['john', 'simon', 'rose', 'tom'];
505541

@@ -558,7 +594,7 @@ public function limitedAskCommand()
558594
* This is a demo for input password. use: <magenta>Interact::askPassword()</magenta>
559595
* @usage {fullCommand}
560596
*/
561-
public function pwdCommand()
597+
public function passwordCommand()
562598
{
563599
$pwd = $this->askPassword();
564600

examples/Controllers/ProcessController.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace Inhere\Console\Examples\Controllers;
1010

1111
use Inhere\Console\Controller;
12+
use Inhere\Console\Utils\ProcessUtil;
1213

1314
/**
1415
* Class ProcessController
@@ -19,4 +20,53 @@ class ProcessController extends Controller
1920
protected static $name = 'process';
2021

2122
protected static $description = 'Some simple process to create and use examples';
23+
24+
protected static function commandAliases()
25+
{
26+
return [
27+
'cpr' => 'childProcess',
28+
'mpr' => 'multiProcess',
29+
'dr' => 'daemonRun',
30+
];
31+
}
32+
33+
/**
34+
* simple process example for child-process
35+
*/
36+
public function childProcessCommand()
37+
{
38+
$ret = ProcessUtil::create(function ($pid) {
39+
echo "print in process $pid";
40+
41+
sleep(5);
42+
});
43+
44+
if ($ret === false) {
45+
$this->output->liteError('current env is not support process create.');
46+
}
47+
}
48+
49+
/**
50+
* simple process example for daemon run
51+
*/
52+
public function daemonRunCommand()
53+
{
54+
$ret = ProcessUtil::daemonRun(function ($pid){
55+
$this->output->info("will running background by new process: $pid");
56+
});
57+
58+
if ($ret === false) {
59+
$this->output->liteError('current env is not support process create.');
60+
}
61+
}
62+
63+
/**
64+
* simple process example for multi-process
65+
* @options
66+
*
67+
*/
68+
public function multiProcessCommand()
69+
{
70+
71+
}
2272
}

examples/routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@
3333
]);
3434

3535
$app->controller(ProcessController::class, null, [
36-
'prc'
36+
'aliases' => 'prc'
3737
]);

src/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ protected function dispatch($name)
280280

281281
// command not found
282282
if (true !== self::fire(self::ON_NOT_FOUND, [$this])) {
283-
$this->output->liteError("The console command '{$name}' not exists!");
283+
$this->output->liteError("The command '{$name}' is not exists in the console application!");
284284

285285
$commands = array_merge($this->getControllerNames(), $this->getCommandNames());
286286

src/Base/AbstractApplication.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public function showHelpInfo($quit = true, string $command = null)
344344
$sep = $this->delimiter;
345345

346346
$this->output->helpPanel([
347-
'usage' => "$script {command} [arg0 arg1=value1 arg2=value2 ...] [--opt -v -h ...]",
347+
'usage' => "$script <info>{command}</info> [arg0 arg1=value1 arg2=value2 ...] [--opt -v -h ...]",
348348
'example' => [
349349
"$script test (run a independent command)",
350350
"$script home{$sep}index (run a command of the group)",
@@ -397,7 +397,7 @@ public function showCommandList($quit = true)
397397
$desPlaceholder = 'No description of the command';
398398

399399
// all console controllers
400-
$controllerArr[] = PHP_EOL . '- <cyan>Group Commands</cyan>';
400+
$controllerArr[] = PHP_EOL . '- <bold>Group Commands</bold>';
401401
$controllers = $this->controllers;
402402
ksort($controllers);
403403

@@ -414,9 +414,9 @@ public function showCommandList($quit = true)
414414
$controllerArr[] = '... No register any group command(controller)';
415415
}
416416

417-
// all independent commands
417+
// all independent commands, Independent, Single, Alone
418418
$commands = $this->commands;
419-
$commandArr[] = PHP_EOL . '- <cyan>Independent Commands</cyan>';
419+
$commandArr[] = PHP_EOL . '- <bold>Alone Commands</bold>';
420420
ksort($commands);
421421

422422
foreach ($commands as $name => $command) {
@@ -448,10 +448,10 @@ public function showCommandList($quit = true)
448448
ksort($internalCommands);
449449

450450
// built in options
451-
$internalOptions = FormatUtil::commandOptions(self::$internalOptions);
451+
$internalOptions = FormatUtil::arrayOptions(self::$internalOptions);
452452

453453
$this->output->mList([
454-
'Usage:' => "$script {command} [arg0 arg1=value1 arg2=value2 ...] [--opt -v -h ...]",
454+
'Usage:' => "$script <info>{command}</info> [arg0 arg1=value1 arg2=value2 ...] [--opt -v -h ...]",
455455
'Options:' => $internalOptions,
456456
'Internal Commands:' => $internalCommands,
457457
'Available Commands:' => array_merge($controllerArr, $commandArr),

src/Controller.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,10 @@ final public function showCommandList()
208208

209209
if ($this->standAlone) {
210210
$name = $sName . ' ';
211-
$usage = "$script <info>{command}</info> [arguments] [options]";
211+
$usage = "$script <info>{command}</info> [arguments ...] [options ...]";
212212
} else {
213213
$name = $sName . $this->delimiter;
214-
$usage = "$script {$name}<info>{command}</info> [arguments] [options]";
214+
$usage = "$script {$name}<info>{command}</info> [arguments ...] [options ...]";
215215
}
216216

217217
$this->output->startBuffer();
@@ -220,9 +220,11 @@ final public function showCommandList()
220220
'Usage:' => $usage,
221221
//'Group Name:' => "<info>$sName</info>",
222222
'Options:' => [
223-
'-h,--help' => 'Show help of the command group or specified command action',
223+
'-h, --help' => 'Show help of the command group or specified command action',
224224
],
225225
'Commands:' => $commands,
226+
], [
227+
'sepChar' => ' ',
226228
]);
227229

228230
$this->write(sprintf(

0 commit comments

Comments
 (0)