Skip to content

Commit 06ccb4d

Browse files
committed
up
1 parent 0caaf39 commit 06ccb4d

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

src/Base/AbstractApplication.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ abstract class AbstractApplication implements ApplicationInterface
3838
'name' => 'My Console',
3939
'version' => '0.5.1',
4040
'publishAt' => '2017.03.24',
41+
'updateAt' => '2017.03.24',
4142
'rootPath' => '',
4243
'hideRootPath' => true,
4344
// 'env' => 'pdt', // dev test pdt
@@ -120,7 +121,7 @@ protected function runtimeCheck()
120121
protected function init()
121122
{
122123
$this->commandName = $this->input->getCommand();
123-
set_exception_handler([$this, 'exceptionHandler']);
124+
set_exception_handler([$this, 'handleException']);
124125
}
125126

126127
/**********************************************************
@@ -153,7 +154,7 @@ public function run($exit = true)
153154
} catch (\Throwable $e) {
154155
self::fire(self::ON_RUN_ERROR, [$e, $this]);
155156
$returnCode = $e->getCode() === 0 ? __LINE__ : $e->getCode();
156-
$this->exceptionHandler($e);
157+
$this->handleException($e);
157158
}
158159

159160
// call 'onAfterRun' service, if it is registered.
@@ -191,7 +192,7 @@ public function stop($code = 0)
191192
* @param \Exception|\Throwable $e
192193
* @throws \Exception
193194
*/
194-
public function exceptionHandler($e)
195+
public function handleException($e)
195196
{
196197
// $this->logger->ex($e);
197198

@@ -227,6 +228,10 @@ protected function filterSpecialCommand($command)
227228
if ($this->input->getSameOpt(['V', 'version'])) {
228229
$this->showVersionInfo();
229230
}
231+
232+
if ($this->input->getSameOpt(['h', 'help'])) {
233+
$this->showHelpInfo();
234+
}
230235
}
231236

232237
if ($this->input->getSameOpt(['no-color'])) {
@@ -282,7 +287,8 @@ public function showHelpInfo($quit = true)
282287
'usage' => "$script [route|command] [arg0 arg1=value1 arg2=value2 ...] [--opt -v -h ...]",
283288
'example' => [
284289
"$script test (run a independent command)",
285-
"$script home{$sep}index (run a command of the group)"
290+
"$script home{$sep}index (run a command of the group)",
291+
"$script home{$sep}index -h (see a command help of the group)",
286292
]
287293
], $quit);
288294
}
@@ -297,12 +303,14 @@ public function showVersionInfo($quit = true)
297303
$name = $this->getMeta('name', 'Console Application');
298304
$version = $this->getMeta('version', 'Unknown');
299305
$publishAt = $this->getMeta('publishAt', 'Unknown');
306+
$updateAt = $this->getMeta('updateAt', 'Unknown');
300307
$phpVersion = PHP_VERSION;
301308
$os = PHP_OS;
302309

303310
$this->output->aList([
304-
"Console Application <info>{$name}</info> Version <comment>$version</comment>(publish at $publishAt)",
305-
'System' => "PHP version <info>$phpVersion</info>, on OS <info>$os</info>, current Date $date",
311+
"\n <info>{$name}</info>, Version <comment>$version</comment>\n",
312+
'System Info' => "PHP version <info>$phpVersion</info>, on <info>$os</info> system",
313+
'Application Info' => "Update at <info>$updateAt</info>, publish at <info>$publishAt</info>(current $date)",
306314
], null, [
307315
'leftChar' => ''
308316
]);
@@ -493,6 +501,14 @@ public function isInternalCommand(string $name): bool
493501
return isset(static::$internalCommands[$name]);
494502
}
495503

504+
/**
505+
* @return string
506+
*/
507+
public function getName()
508+
{
509+
return $this->meta['name'];
510+
}
511+
496512
/**
497513
* set meta info
498514
* @param array $meta
@@ -506,9 +522,9 @@ public function setMeta(array $meta)
506522

507523
/**
508524
* get meta info
509-
* @param null $name
510-
* @param null $default
511-
* @return array
525+
* @param null|string $name
526+
* @param null|string $default
527+
* @return array|string
512528
*/
513529
public function getMeta($name = null, $default = null)
514530
{

0 commit comments

Comments
 (0)