From bcb250f3911d0900e7a479c030b74e9edb39a773 Mon Sep 17 00:00:00 2001 From: Ahmed Ashraf Date: Sat, 9 Apr 2016 15:19:38 +0200 Subject: [PATCH 1/2] specify the languages to display --- src/Commands/ShowCommand.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Commands/ShowCommand.php b/src/Commands/ShowCommand.php index 1ac01ae..a43122b 100644 --- a/src/Commands/ShowCommand.php +++ b/src/Commands/ShowCommand.php @@ -14,7 +14,7 @@ class ShowCommand extends Command * * @var string */ - protected $signature = 'langman:show {key} {--c|close}'; + protected $signature = 'langman:show {key} {--c|close} {--lang=}'; /** * The name and signature of the console command. @@ -51,6 +51,13 @@ class ShowCommand extends Command */ protected $files; + /** + * Array of selected languages. + * + * @var array + */ + protected $languages; + /** * ListCommand constructor. * @@ -74,8 +81,14 @@ public function handle() $this->files = $this->filesFromKey(); + $this->languages = $this->manager->languages(); + + if($this->option('lang') != null){ + $this->languages = explode(',',$this->option('lang')); + } + $this->table( - array_merge(['key'], $this->manager->languages()), + array_merge(['key'], $this->languages), $this->tableRows() ); } @@ -87,8 +100,6 @@ public function handle() */ private function tableRows() { - $allLanguages = $this->manager->languages(); - $output = []; $filesContent = []; @@ -110,7 +121,7 @@ private function tableRows() foreach ($output as $key => $values) { $original = []; - foreach ($allLanguages as $languageKey) { + foreach ($this->languages as $languageKey) { $original[$languageKey] = isset($values[$languageKey]) ? $values[$languageKey] : ' MISSING '; } From 10e2324f9a82e7bbc7d0d9929a0179292908fc9b Mon Sep 17 00:00:00 2001 From: Ahmed Ashraf Date: Sat, 9 Apr 2016 15:47:23 +0200 Subject: [PATCH 2/2] Validate option lang --- src/Commands/ShowCommand.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Commands/ShowCommand.php b/src/Commands/ShowCommand.php index a43122b..3bab72d 100644 --- a/src/Commands/ShowCommand.php +++ b/src/Commands/ShowCommand.php @@ -82,9 +82,13 @@ public function handle() $this->files = $this->filesFromKey(); $this->languages = $this->manager->languages(); - - if($this->option('lang') != null){ - $this->languages = explode(',',$this->option('lang')); + + if ($this->option('lang') != null) { + $languages = explode(',', $this->option('lang')); + if (!empty($diffLangagues = array_diff($languages, $this->languages))) { + return $this->error('Unknown Langauges [ '.implode($diffLangagues,',').' ]'); + } + $this->languages = explode(',', $this->option('lang')); } $this->table( @@ -106,11 +110,11 @@ private function tableRows() foreach ($this->files as $languageKey => $file) { foreach ($filesContent[$languageKey] = Arr::dot($this->manager->getFileContent($file)) as $key => $value) { - if (! $this->shouldShowKey($key)) { + if (!$this->shouldShowKey($key)) { continue; } - $output[$key]['key'] = $key; + $output[$key]['key'] = $key; $output[$key][$languageKey] = $value; } } @@ -190,11 +194,11 @@ private function shouldShowKey($key) return true; } - if (! $this->option('close') && $key != $this->key) { + if (!$this->option('close') && $key != $this->key) { return false; } - if ($this->option('close') && ! Str::contains($key, $this->key)) { + if ($this->option('close') && !Str::contains($key, $this->key)) { return false; } }