Skip to content

Commit

Permalink
Added flags to command
Browse files Browse the repository at this point in the history
  • Loading branch information
tylercd100 committed Mar 13, 2018
1 parent c1a4cea commit 4db34d1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to `laravel-licenser` will be documented in this file.

### 3.5.7
- Added flags to command

### 3.5.6
- Fixed console output errors

Expand Down
24 changes: 14 additions & 10 deletions src/Commands/LicenseUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class LicenseUpdate extends Command
*
* @var string
*/
protected $signature = 'license:update';
protected $signature = 'license:update {--quantity=?} {--license=?} {--owner_type=?} {--owner_id=?}';

/**
* The console command description.
Expand Down Expand Up @@ -45,7 +45,7 @@ public function handle()

protected function getQuantity($current = 0)
{
return intval($this->ask("Please select a new maximum value for this license. (The current maximum is {$current})"));
return intval($this->option("quantity") ?: $this->ask("Please select a new maximum value for this license. (The current maximum is {$current})"));
}

protected function selectLicense($where = [])
Expand All @@ -65,15 +65,19 @@ protected function selectOwnerId($where = [])

final protected function getSelection($column, $where = [])
{
try {
$options = DB::table('licenses')->where($where)->groupBy($column)->get([$column])->pluck($column)->toArray();
if(count($options) > 1) {
$selection = $this->choice("Select a {$column}", $options);
} else {
$selection = $options[0];
$selection = $this->option($column) ?: null;

if (!$selection) {
try {
$options = DB::table('licenses')->where($where)->groupBy($column)->get([$column])->pluck($column)->toArray();
if(count($options) > 1) {
$selection = $this->choice("Select a {$column}", $options);
} else {
$selection = $options[0];
}
} catch (\OutOfBoundsException $e) {
throw new \Exception("Could not find a {$column}", 1, $e);
}
} catch (\OutOfBoundsException $e) {
throw new \Exception("Could not find a {$column}", 1, $e);
}

$this->info("Selected: {$selection}");
Expand Down

0 comments on commit 4db34d1

Please sign in to comment.