Skip to content

Commit

Permalink
Feature/defaults to questions (#84)
Browse files Browse the repository at this point in the history
* Added -y|--yes defaults to the questions if you are sure.

* Small refactor.
  • Loading branch information
SanderAtom authored and timneutkens committed Oct 17, 2017
1 parent 85553cd commit 5cef044
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions cli/valet.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,9 @@
/**
* Create database
*/
$app->command('db [run] [name] [optional]', function ($input, $output, $run, $name, $optional) {
$app->command('db [run] [name] [optional] [-y|--yes]', function ($input, $output, $run, $name, $optional) {
$helper = $this->getHelperSet()->get('question');
$defaults = $input->getOptions();

if($run === 'list' || $run === 'ls') {
Mysql::listDatabases();
Expand All @@ -441,10 +442,12 @@
}

if($run === 'drop') {
$question = new ConfirmationQuestion('Are you sure you want to delete the database? [y/N] ', false);
if (!$helper->ask($input, $output, $question)) {
warning('Aborted');
return;
if(!$defaults['yes']) {
$question = new ConfirmationQuestion('Are you sure you want to delete the database? [y/N] ', FALSE);
if (!$helper->ask($input, $output, $question)) {
warning('Aborted');
return;
}
}
$databaseName = Mysql::dropDatabase($name);

Expand All @@ -457,10 +460,12 @@
}

if($run === 'reset') {
$question = new ConfirmationQuestion('Are you sure you want to reset the database? [y/N] ', false);
if (!$helper->ask($input, $output, $question)) {
warning('Aborted');
return;
if(!$defaults['yes']) {
$question = new ConfirmationQuestion('Are you sure you want to reset the database? [y/N] ', FALSE);
if (!$helper->ask($input, $output, $question)) {
warning('Aborted');
return;
}
}

$dropped = Mysql::dropDatabase($name);
Expand Down Expand Up @@ -500,10 +505,12 @@
}

if($run === 'reimport') {
$question = new ConfirmationQuestion('Are you sure you want to reimport the database? [y/N] ', false);
if (!$helper->ask($input, $output, $question)) {
warning('Aborted');
return;
if(!$defaults['yes']) {
$question = new ConfirmationQuestion('Are you sure you want to reimport the database? [y/N] ', FALSE);
if (!$helper->ask($input, $output, $question)) {
warning('Aborted');
return;
}
}
info('Resetting database, importing database...');
if(!$name) {
Expand Down

0 comments on commit 5cef044

Please sign in to comment.