Skip to content

Commit 4db34d1

Browse files
committed
Added flags to command
1 parent c1a4cea commit 4db34d1

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

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

5+
### 3.5.7
6+
- Added flags to command
7+
58
### 3.5.6
69
- Fixed console output errors
710

src/Commands/LicenseUpdate.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class LicenseUpdate extends Command
1212
*
1313
* @var string
1414
*/
15-
protected $signature = 'license:update';
15+
protected $signature = 'license:update {--quantity=?} {--license=?} {--owner_type=?} {--owner_id=?}';
1616

1717
/**
1818
* The console command description.
@@ -45,7 +45,7 @@ public function handle()
4545

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

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

6666
final protected function getSelection($column, $where = [])
6767
{
68-
try {
69-
$options = DB::table('licenses')->where($where)->groupBy($column)->get([$column])->pluck($column)->toArray();
70-
if(count($options) > 1) {
71-
$selection = $this->choice("Select a {$column}", $options);
72-
} else {
73-
$selection = $options[0];
68+
$selection = $this->option($column) ?: null;
69+
70+
if (!$selection) {
71+
try {
72+
$options = DB::table('licenses')->where($where)->groupBy($column)->get([$column])->pluck($column)->toArray();
73+
if(count($options) > 1) {
74+
$selection = $this->choice("Select a {$column}", $options);
75+
} else {
76+
$selection = $options[0];
77+
}
78+
} catch (\OutOfBoundsException $e) {
79+
throw new \Exception("Could not find a {$column}", 1, $e);
7480
}
75-
} catch (\OutOfBoundsException $e) {
76-
throw new \Exception("Could not find a {$column}", 1, $e);
7781
}
7882

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

0 commit comments

Comments
 (0)