diff --git a/CHANGELOG.md b/CHANGELOG.md index 7498ff3..65fa83e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Commands/LicenseUpdate.php b/src/Commands/LicenseUpdate.php index f4cb6cb..0cebcb5 100644 --- a/src/Commands/LicenseUpdate.php +++ b/src/Commands/LicenseUpdate.php @@ -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. @@ -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 = []) @@ -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}");