Skip to content

Commit

Permalink
Merge pull request #5 from utopia-php/feat-cli-update
Browse files Browse the repository at this point in the history
  • Loading branch information
lohanidamodar authored Oct 28, 2022
2 parents 5a3640f + 07e8251 commit 9cebec3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"ext-json": "*",
"ext-redis": "*",
"utopia-php/framework": "0.22.*",
"utopia-php/cli": "0.13.*"
"utopia-php/cli": "0.14.*"
},
"require-dev": {
"phpunit/phpunit": "^9.3",
Expand Down
44 changes: 33 additions & 11 deletions src/Platform/Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,8 @@ protected function initHttp(): void
}
}

if ($hook instanceof Route) {
foreach ($action->getLabels() as $key => $label) {
$hook->label($key, $label);
}
foreach ($action->getLabels() as $key => $label) {
$hook->label($key, $label);
}

$hook->action($action->getCallback());
Expand All @@ -113,18 +111,42 @@ protected function initCLI(): void
$this->cli ??= new CLI();
foreach ($this->services[Service::TYPE_CLI] as $service) {
foreach ($service->getActions() as $key => $action) {
$task = $this->cli->task($key);
$task
->desc($action->getDesc() ?? '')
->action($action->getCallback());
switch ($action->getType()) {
case Action::TYPE_INIT:
$hook = $this->cli->init();
break;
case Action::TYPE_ERROR:
$hook = $this->cli->error();
break;
case Action::TYPE_SHUTDOWN:
$hook = $this->cli->shutdown();
break;
case Action::TYPE_DEFAULT:
default:
$hook = $this->cli->task($key);
break;
}
$hook
->groups($action->getGroups())
->desc($action->getDesc() ?? '');

foreach ($action->getParams() as $key => $param) {
$task->param($key, $param['default'], $param['validator'], $param['description'], $param['optional']);
foreach ($action->getOptions() as $key => $option) {
switch ($option['type']) {
case 'param':
$key = substr($key, stripos($key, ':') + 1);
$hook->param($key, $option['default'], $option['validator'], $option['description'], $option['optional'], $option['injections']);
break;
case 'injection':
$hook->inject($option['name']);
break;
}
}

foreach ($action->getLabels() as $key => $label) {
$task->label($key, $label);
$hook->label($key, $label);
}

$hook->action($action->getCallback());
}
}
}
Expand Down

0 comments on commit 9cebec3

Please sign in to comment.