diff --git a/composer.json b/composer.json index ecefbcf..6b442d3 100755 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ }, "require": { "php": ">=7.4", - "utopia-php/servers": "0.3.*" + "utopia-php/servers": "dev-feat-param-aliases" }, "require-dev": { "utopia-php/console": "0.0.*", diff --git a/composer.lock b/composer.lock index f39de59..90b0c06 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "eae8ed34595bee99463b92923f9e6210", + "content-hash": "39d973bfe74e36b1f3431af3e4ac21ab", "packages": [ { "name": "psr/container", @@ -61,16 +61,16 @@ }, { "name": "utopia-php/di", - "version": "0.3.1", + "version": "0.3.2", "source": { "type": "git", "url": "https://github.com/utopia-php/di.git", - "reference": "68873b7267842315d01d82a83b988bae525eab31" + "reference": "07025d721ed5d9be27932e8e640acf1467fc4b9d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/di/zipball/68873b7267842315d01d82a83b988bae525eab31", - "reference": "68873b7267842315d01d82a83b988bae525eab31", + "url": "https://api.github.com/repos/utopia-php/di/zipball/07025d721ed5d9be27932e8e640acf1467fc4b9d", + "reference": "07025d721ed5d9be27932e8e640acf1467fc4b9d", "shasum": "" }, "require": { @@ -106,22 +106,22 @@ ], "support": { "issues": "https://github.com/utopia-php/di/issues", - "source": "https://github.com/utopia-php/di/tree/0.3.1" + "source": "https://github.com/utopia-php/di/tree/0.3.2" }, - "time": "2026-03-13T05:47:23+00:00" + "time": "2026-03-21T07:42:10+00:00" }, { "name": "utopia-php/servers", - "version": "0.3.0", + "version": "dev-feat-param-aliases", "source": { "type": "git", "url": "https://github.com/utopia-php/servers.git", - "reference": "235be31200df9437fc96a1c270ffef4c64fafe52" + "reference": "24bbd8fbb6550bc72f2816d9b0c3b690e38e17fa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/servers/zipball/235be31200df9437fc96a1c270ffef4c64fafe52", - "reference": "235be31200df9437fc96a1c270ffef4c64fafe52", + "url": "https://api.github.com/repos/utopia-php/servers/zipball/24bbd8fbb6550bc72f2816d9b0c3b690e38e17fa", + "reference": "24bbd8fbb6550bc72f2816d9b0c3b690e38e17fa", "shasum": "" }, "require": { @@ -160,22 +160,22 @@ ], "support": { "issues": "https://github.com/utopia-php/servers/issues", - "source": "https://github.com/utopia-php/servers/tree/0.3.0" + "source": "https://github.com/utopia-php/servers/tree/feat-param-aliases" }, - "time": "2026-03-13T11:31:42+00:00" + "time": "2026-05-04T11:57:44+00:00" }, { "name": "utopia-php/validators", - "version": "0.2.0", + "version": "0.2.2", "source": { "type": "git", "url": "https://github.com/utopia-php/validators.git", - "reference": "30b6030a5b100fc1dff34506e5053759594b2a20" + "reference": "5d7d494e64457cd4eb67fdcfd9481f2c89796aa6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/validators/zipball/30b6030a5b100fc1dff34506e5053759594b2a20", - "reference": "30b6030a5b100fc1dff34506e5053759594b2a20", + "url": "https://api.github.com/repos/utopia-php/validators/zipball/5d7d494e64457cd4eb67fdcfd9481f2c89796aa6", + "reference": "5d7d494e64457cd4eb67fdcfd9481f2c89796aa6", "shasum": "" }, "require": { @@ -205,9 +205,9 @@ ], "support": { "issues": "https://github.com/utopia-php/validators/issues", - "source": "https://github.com/utopia-php/validators/tree/0.2.0" + "source": "https://github.com/utopia-php/validators/tree/0.2.2" }, - "time": "2026-01-13T09:16:51+00:00" + "time": "2026-04-27T16:30:24+00:00" } ], "packages-dev": [ @@ -2298,12 +2298,14 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": { + "utopia-php/servers": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { "php": ">=7.4" }, "platform-dev": {}, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.9.0" } diff --git a/src/CLI/CLI.php b/src/CLI/CLI.php index e4c96e2..15f1862 100644 --- a/src/CLI/CLI.php +++ b/src/CLI/CLI.php @@ -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); diff --git a/tests/CLI/CLITest.php b/tests/CLI/CLITest.php index 3abb6d9..354ca25 100755 --- a/tests/CLI/CLITest.php +++ b/tests/CLI/CLITest.php @@ -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); + } }