Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"require": {
"php": ">=7.4",
"utopia-php/servers": "0.3.*"
"utopia-php/servers": "dev-feat-param-aliases"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Dev-branch dependency should not be merged as-is

"utopia-php/servers": "dev-feat-param-aliases" pins the dependency to a mutable development branch rather than a tagged release. If the branch is force-pushed or rebased after this PR merges, composer install on a fresh checkout will silently pull different code. This should be updated to a stable version tag (e.g. "0.3.*" or a new patch release) once the feature branch is merged into utopia-php/servers.

},
"require-dev": {
"utopia-php/console": "0.0.*",
Expand Down
44 changes: 23 additions & 21 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion src/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,18 @@ protected function getParams(Hook $hook): array
$params = [];

foreach ($hook->getParams() as $key => $param) {
$value = (isset($this->args[$key])) ? $this->args[$key] : $param['default'];
$value = $param['default'];

if (isset($this->args[$key])) {
$value = $this->args[$key];
} else {
foreach ($param['aliases'] ?? [] as $alias) {
if (isset($this->args[$alias])) {
$value = $this->args[$alias];
break;
}
}
}

$this->validate($key, $param, $value);

Expand Down
20 changes: 20 additions & 0 deletions tests/CLI/CLITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,4 +427,24 @@ public function testEscaping()

$this->assertEquals($database, $result);
}

public function testParamAliases()
{
ob_start();

$cli = new CLI(new Generic(), ['test.php', 'build', '--e=me@example.com']); // Mock command request using alias

$cli
->task('build')
->param('email', null, new Text(0), 'Valid email address', false, [], false, false, '', null, ['e', 'em'])
->action(function ($email) {
echo $email;
});

$cli->run();

$result = ob_get_clean();

$this->assertEquals('me@example.com', $result);
}
}
Loading