Skip to content

Commit

Permalink
Added guards to cli output and command registration.
Browse files Browse the repository at this point in the history
  • Loading branch information
jstoone committed Nov 15, 2016
1 parent 0d2ae03 commit e0bfe44
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/Commands/CommitToFutureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public function handle()
->uncommitted()
->get();


if($futures->isEmpty()) {
$this->outputMessage('No future plans for today.');
return;
}

$futures->each(function(Future $future) use ($today) {
$modelWithFuture = $future->futureable;

Expand All @@ -54,5 +60,27 @@ public function handle()
->commit();
});

$this->outputMessage("{$futures->count()} futures updated.");
}


/**
* Write a line to the commandline
*
* @return void
*/
private function outputMessage($message)
{
$laravel = $this->laravel ?: false;

if( ! $laravel) {
return;
}

if( ! $laravel->runningInConsole()) {
return;
}

$this->info($message);
}
}
4 changes: 3 additions & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public function boot()
{
$this->loadMigrationsFrom(__DIR__.'/../migrations');

$this->commands(CommitToFutureCommand::class);
if($this-app->runningInConsole()) {
$this->commands(CommitToFutureCommand::class);
}
}

/**
Expand Down

0 comments on commit e0bfe44

Please sign in to comment.