Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Make port as option name #249

Merged
merged 2 commits into from
Dec 2, 2023
Merged
Changes from 1 commit
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
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-read string $port
* @property-read 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
Loading