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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #886 +/- ##
============================================
- Coverage 68.57% 67.72% -0.86%
- Complexity 708 719 +11
============================================
Files 139 139
Lines 1750 1772 +22
============================================
Hits 1200 1200
- Misses 550 572 +22
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, but I believe a better approach is to opt for the standard --no-interaction
flag. Something like this:
private function inNoInteractionMode(): bool
{
return (bool) $this->getOption('no-interaction');
}
public function setUpAdminAccount(): void
{
if ($this->inNoInteractionMode()) {
// use .env creds, ready to explode if they're not provided.
} else {
// collect interactively, just like current
}
}
Do you think you can tackle this?
Hi, thank you for the quick review, I just added the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks great. A couple teeny-tiny changes and I believe we're all set!
app/Console/Commands/InitCommand.php
Outdated
if (!$name) { | ||
$name = $this->ask('Your name'); | ||
if ($this->inNoInteractionMode()) { | ||
$name = config('koel.admin.name'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
@@ -121,26 +125,21 @@ private function setUpDatabase(): void | |||
]); | |||
} | |||
|
|||
private function inNoInteractionMode(): bool | |||
{ | |||
return (bool) $this->option('no-interaction'); |
There was a problem hiding this comment.
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()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's option()
, https://laravel.com/docs/5.7/artisan#retrieving-input 😃
app/Console/Commands/InitCommand.php
Outdated
@@ -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'); |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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
app/Console/Commands/InitCommand.php
Outdated
return; | ||
} | ||
|
||
$this->error('The path '.$path.' does not exist or not readable. Skipping.'); |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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
app/Console/Commands/InitCommand.php
Outdated
$this->error('The path '.$path.' does not exist or not readable. Skipping.'); | ||
return; | ||
|
||
} else { |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the else
is needed in case the user runs koel:init
in interactive mode, like in https://github.com/phanan/koel/pull/886/files/5b9c0342097fd311e2cf7301d5b600eb1fb68ebf#diff-a47e75fc23aa87b0255a42a63499a828R140
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@javier-lopez Sorry I kind of butchered your PR with some fixes on my own :) |
* Use ADMIN_* variables if available to create the admin account * Add APP_MEDIA_PATH for media directory * Use the standard --no-interaction flag to koel:init * Undo variable aligment and code formatting * Prefer early return over else, add new line before return statements * Some fixes
As per e1b68cc#diff-ac5db72ed5e3c5612246e80cb231cacf (Dec 3, 2017), the admin account is NOT set in the
.env
file and created during initial database seeding anymore, therefore it's required to run:In interactive mode to configure koel, such process can be automatized with expect but IMHO it could be better if it uses environment variables when available.
This PR re enable:
And add:
To be able to run
$ php artisan koel:init
in non interactive mode