55use Illuminate \Console \Command ;
66use Illuminate \Support \Arr ;
77use Illuminate \Support \Str ;
8+ use Symfony \Component \Console \Exception \InvalidArgumentException ;
89use Themsaid \Langman \Manager ;
910
1011class ShowCommand extends Command
@@ -52,7 +53,7 @@ class ShowCommand extends Command
5253 protected $ files ;
5354
5455 /**
55- * Array of selected languages.
56+ * Array of displayable languages.
5657 *
5758 * @var array
5859 */
@@ -81,14 +82,12 @@ public function handle()
8182
8283 $ this ->files = $ this ->filesFromKey ();
8384
84- $ this ->languages = $ this ->manager ->languages ();
85+ try {
86+ $ this ->languages = $ this ->getLanguages ();
87+ } catch (InvalidArgumentException $ e ) {
88+ $ this ->error ($ e ->getMessage ());
8589
86- if ($ this ->option ('lang ' ) != null ) {
87- $ languages = explode (', ' , $ this ->option ('lang ' ));
88- if (!empty ($ diffLangagues = array_diff ($ languages , $ this ->languages ))) {
89- return $ this ->error ('Unknown Langauges [ ' .implode ($ diffLangagues ,', ' ).' ] ' );
90- }
91- $ this ->languages = explode (', ' , $ this ->option ('lang ' ));
90+ return ;
9291 }
9392
9493 $ this ->table (
@@ -110,11 +109,11 @@ private function tableRows()
110109
111110 foreach ($ this ->files as $ languageKey => $ file ) {
112111 foreach ($ filesContent [$ languageKey ] = Arr::dot ($ this ->manager ->getFileContent ($ file )) as $ key => $ value ) {
113- if (!$ this ->shouldShowKey ($ key )) {
112+ if (! $ this ->shouldShowKey ($ key )) {
114113 continue ;
115114 }
116115
117- $ output [$ key ]['key ' ] = $ key ;
116+ $ output [$ key ]['key ' ] = $ key ;
118117 $ output [$ key ][$ languageKey ] = $ value ;
119118 }
120119 }
@@ -194,15 +193,37 @@ private function shouldShowKey($key)
194193 return true ;
195194 }
196195
197- if (!$ this ->option ('close ' ) && $ key != $ this ->key ) {
196+ if (! $ this ->option ('close ' ) && $ key != $ this ->key ) {
198197 return false ;
199198 }
200199
201- if ($ this ->option ('close ' ) && !Str::contains ($ key , $ this ->key )) {
200+ if ($ this ->option ('close ' ) && ! Str::contains ($ key , $ this ->key )) {
202201 return false ;
203202 }
204203 }
205204
206205 return true ;
207206 }
207+
208+ /**
209+ * Get the languages to be displayed in the command output.
210+ *
211+ * @return array
212+ */
213+ private function getLanguages ()
214+ {
215+ $ allLanguages = $ this ->manager ->languages ();
216+
217+ if (! $ this ->option ('lang ' )) {
218+ return $ allLanguages ;
219+ }
220+
221+ $ userLanguages = explode (', ' , (string ) $ this ->option ('lang ' ));
222+
223+ if ($ missingLanguages = array_diff ($ userLanguages , $ allLanguages )) {
224+ throw new InvalidArgumentException ('Unknown Language(s) [ ' .implode (', ' , $ missingLanguages ).']. ' );
225+ }
226+
227+ return $ userLanguages ;
228+ }
208229}
0 commit comments