Skip to content

Commit

Permalink
[Refactor] Make port as option name (#249)
Browse files Browse the repository at this point in the history
* refactor: make port as option name

- port using option instead of command name
  • Loading branch information
SonyPradana authored Dec 2, 2023
1 parent a50a845 commit 99b668a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/System/Integrate/Console/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
use System\Console\Traits\PrintHelpTrait;

/**
* @property bool|null $expose
* @property string $port
* @property bool $expose
*/
class ServeCommand extends Command
{
Expand All @@ -26,6 +27,7 @@ class ServeCommand extends Command
'pattern' => 'serve',
'fn' => [ServeCommand::class, 'main'],
'default' => [
'port' => 8080,
'expose' => false,
],
],
Expand All @@ -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
Expand Down

0 comments on commit 99b668a

Please sign in to comment.