Skip to content

Commit

Permalink
Now trying auto insert whenever a command is run
Browse files Browse the repository at this point in the history
  • Loading branch information
matgeroe committed Apr 29, 2019
1 parent 64a9482 commit 4b53035
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
9 changes: 8 additions & 1 deletion src/Commands/DisableFeatureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Console\Command;
use MatthiasWilbrink\FeatureToggle\Exceptions\FeatureNotFoundException;
use MatthiasWilbrink\FeatureToggle\Exceptions\NoFeaturesException;
use MatthiasWilbrink\FeatureToggle\Exceptions\NoToggableFeaturesException;
use MatthiasWilbrink\FeatureToggle\Facades\Feature;
use MatthiasWilbrink\FeatureToggle\Models\Feature as FeatureModel;

Expand All @@ -31,6 +32,9 @@ class DisableFeatureCommand extends Command
*/
public function handle()
{

$this->call('feature:list');

try {
$featureName = $this->choice('Which feature would you like to turn off?', Feature::options(FeatureModel::ON));

Expand All @@ -45,7 +49,10 @@ public function handle()
} catch (FeatureNotFoundException $exception) {
$this->warn("Feature {$exception->featureName} could not be found");
} catch (NoFeaturesException $exception) {
$this->call('feature:list');
$this->warn('Please define features in the config file');
} catch (NoToggableFeaturesException $exception){

}

}
}
8 changes: 7 additions & 1 deletion src/Commands/EnableFeatureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Console\Command;
use MatthiasWilbrink\FeatureToggle\Exceptions\FeatureNotFoundException;
use MatthiasWilbrink\FeatureToggle\Exceptions\NoFeaturesException;
use MatthiasWilbrink\FeatureToggle\Exceptions\NoToggableFeaturesException;
use MatthiasWilbrink\FeatureToggle\Facades\Feature;
use MatthiasWilbrink\FeatureToggle\Models\Feature as FeatureModel;

Expand All @@ -31,6 +32,9 @@ class EnableFeatureCommand extends Command
*/
public function handle()
{

$this->call('feature:list');

try {
$featureName = $this->choice('Which feature would you like to turn on?', Feature::options(FeatureModel::OFF));

Expand All @@ -45,7 +49,9 @@ public function handle()
} catch (FeatureNotFoundException $exception) {
$this->warn("Feature {$exception->featureName} could not be found");
} catch (NoFeaturesException $exception) {
$this->call('feature:list');
$this->warn('Please define features in the config file');
}catch (NoToggableFeaturesException $exception){

}
}
}
11 changes: 6 additions & 5 deletions src/Commands/ListFeaturesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ class ListFeaturesCommand extends Command
*/
public function handle()
{
if (empty(Feature::allArray())) {
$this->call('feature:create');
}

if (empty(Feature::allArray())) {
$this->call('feature:create');

$featureArray = Feature::allArray();

if (empty($featureArray)) {
$this->warn('Please define features in the config file');
} else {
$this->table(['id', 'name', 'state', 'created_at', 'updated_at'], Feature::allArray());
$this->table(['id', 'name', 'state', 'created at', 'updated at'], $featureArray);
}

}
Expand Down
8 changes: 8 additions & 0 deletions src/Exceptions/NoToggableFeaturesException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace MatthiasWilbrink\FeatureToggle\Exceptions;

class NoToggableFeaturesException extends \Exception
{

}
10 changes: 8 additions & 2 deletions src/Managers/FeatureManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Support\Facades\Config;
use MatthiasWilbrink\FeatureToggle\Exceptions\FeatureNotFoundException;
use MatthiasWilbrink\FeatureToggle\Exceptions\NoFeaturesException;
use MatthiasWilbrink\FeatureToggle\Exceptions\NoToggableFeaturesException;
use MatthiasWilbrink\FeatureToggle\Models\Feature;

/**
Expand Down Expand Up @@ -139,12 +140,17 @@ public function allArray()
* @param int $filter
* @return array
* @throws NoFeaturesException
* @throws NoToggableFeaturesException
*/
public function options(int $filter)
{
$options = $this->all()->where('state', $filter);
$options = $this->all();
if ($options->isNotEmpty()) {
return $options->pluck('name')->toArray();
$options = $options->where('state', $filter);
if ($options->isNotEmpty()) {
return $options->pluck('name')->toArray();
}
throw new NoToggableFeaturesException();
}
throw new NoFeaturesException();
}
Expand Down

0 comments on commit 4b53035

Please sign in to comment.