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

Non interactive koel:init #886

Merged
merged 6 commits into from Jan 1, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
73 changes: 50 additions & 23 deletions app/Console/Commands/InitCommand.php
Expand Up @@ -49,6 +49,10 @@ public function handle(): void
$this->comment('Remember, you can always install/upgrade manually following the guide here:');
$this->info('📙 '.config('koel.misc.docs_url').PHP_EOL);

if ($this->inNoInteractionMode()) {
$this->info('Running in --no-interaction mode');
Copy link
Member

Choose a reason for hiding this comment

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

How about Running in no-interaction mode (without the double hyphen)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, modifying in next commit

}

$this->maybeGenerateAppKey();
$this->maybeGenerateJwtSecret();
$this->maybeSetUpDatabase();
Expand Down Expand Up @@ -121,22 +125,33 @@ private function setUpDatabase(): void
]);
}

private function inNoInteractionMode(): bool
{
return (bool) $this->option('no-interaction');
Copy link
Member

Choose a reason for hiding this comment

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

Is it option() or hasOption()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

private function setUpAdminAccount(): void
{
$this->info("Let's create the admin account.");
$name = $this->ask('Your name');
$email = $this->ask('Your email address');
$passwordConfirmed = false;
$password = null;

while (!$passwordConfirmed) {
$password = $this->secret('Your desired password');
$confirmation = $this->secret('Again, just to make sure');

if ($confirmation !== $password) {
$this->error('That doesn\'t match. Let\'s try again.');
} else {
$passwordConfirmed = true;
if ($this->inNoInteractionMode()) {
$name = config('koel.admin.name');
Copy link
Member

Choose a reason for hiding this comment

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

Please don't align variable assignments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, undoing in next commit

$email = config('koel.admin.email');
$password = config('koel.admin.password');
} else {
$name = $this->ask('Your name');
$email = $this->ask('Your email address');
$passwordConfirmed = false;
$password = null;

while (!$passwordConfirmed) {
$password = $this->secret('Your desired password');
$confirmation = $this->secret('Again, just to make sure');

if ($confirmation !== $password) {
$this->error('That doesn\'t match. Let\'s try again.');
} else {
$passwordConfirmed = true;
}
}
}

Expand All @@ -154,22 +169,34 @@ private function maybeSetMediaPath(): void
return;
}

$this->info('The absolute path to your media directory. If this is skipped (left blank) now, you can set it later via the web interface.');

while (true) {
$path = $this->ask('Media path', false);

if ($path === false) {
return;
}
if ($this->inNoInteractionMode()) {
$path = config('koel.media_path');

if (is_dir($path) && is_readable($path)) {
Setting::set('media_path', $path);

return;
}

$this->error('The path does not exist or not readable. Try again.');
$this->error('The path '.$path.' does not exist or not readable. Skipping.');
Copy link
Member

Choose a reason for hiding this comment

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

We can return early here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just added a return statement after the error message


} else {
Copy link
Member

Choose a reason for hiding this comment

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

We don't need else if early return has been used (that's the whole point of early return here).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

No, you don't need else because you have return'ed. Also, please add a new line before return statements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I finally saw why it didn't required an else statement =P, I also tried to add new lines before returns, except when they are alone or around single lines.


$this->info('The absolute path to your media directory. If this is skipped (left blank) now, you can set it later via the web interface.');

while (true) {
$path = $this->ask('Media path', false);

if ($path === false) {
return;
}

if (is_dir($path) && is_readable($path)) {
Setting::set('media_path', $path);
return;
}

$this->error('The path does not exist or not readable. Try again.');
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions config/koel.php
Expand Up @@ -26,6 +26,8 @@
|
*/

'media_path' => env('APP_MEDIA_PATH', '/media'),

'sync' => [
'timeout' => env('APP_MAX_SCAN_TIME', 600),
],
Expand Down