From 155290d654e23e50101b7076753acce8dd465d59 Mon Sep 17 00:00:00 2001 From: SonyPradana Date: Sat, 2 Dec 2023 14:40:37 +0700 Subject: [PATCH 1/2] refactor: make port as option name - port using option instead of command name --- src/System/Integrate/Console/ServeCommand.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/System/Integrate/Console/ServeCommand.php b/src/System/Integrate/Console/ServeCommand.php index 04a3211f..55db8de4 100644 --- a/src/System/Integrate/Console/ServeCommand.php +++ b/src/System/Integrate/Console/ServeCommand.php @@ -10,7 +10,8 @@ use System\Console\Traits\PrintHelpTrait; /** - * @property bool|null $expose + * @property-read string $port + * @property-read bool $expose */ class ServeCommand extends Command { @@ -26,6 +27,7 @@ class ServeCommand extends Command 'pattern' => 'serve', 'fn' => [ServeCommand::class, 'main'], 'default' => [ + 'port' => 8080, 'expose' => false, ], ], @@ -41,29 +43,28 @@ public function printHelp() 'serve' => 'Serve server with port number (default 8080)', ], 'options' => [ + '--port' => 'Serve with costume port', '--expose' => 'Make server run public network', ], 'relation' => [ - 'serve' => ['[port]', '--expose'], + 'serve' => ['--port', '--expose'], ], ]; } public function main(): void { - $port = $this->OPTION[0] ?? '8080'; - $port = $port == '' ? '8080' : $port; + $port = $this->port; $localIP = gethostbyname(gethostname()); $print = new Style('Server runing add:'); $print ->newLines() - ->push('Local')->tabs()->push("http://localhost:$port")->textBlue() - ->newLines(); + ->push('Local')->tabs()->push("http://localhost:$port")->textBlue(); if ($this->expose) { - $print->push('Network')->tabs()->push("http://$localIP:$port")->textBlue(); + $print->newLines()->push('Network')->tabs()->push("http://$localIP:$port")->textBlue(); } $print From 2aba0c0525cf9f0fa92540f62bdbb780ece19066 Mon Sep 17 00:00:00 2001 From: SonyPradana Date: Sat, 2 Dec 2023 14:46:48 +0700 Subject: [PATCH 2/2] lint --- src/System/Integrate/Console/ServeCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System/Integrate/Console/ServeCommand.php b/src/System/Integrate/Console/ServeCommand.php index 55db8de4..8773a360 100644 --- a/src/System/Integrate/Console/ServeCommand.php +++ b/src/System/Integrate/Console/ServeCommand.php @@ -10,8 +10,8 @@ use System\Console\Traits\PrintHelpTrait; /** - * @property-read string $port - * @property-read bool $expose + * @property string $port + * @property bool $expose */ class ServeCommand extends Command {