Skip to content

Commit 30e53f0

Browse files
committed
checks to alias syntax
1 parent b24e0c7 commit 30e53f0

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/Commands/NovaLangPublish.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,20 +157,34 @@ protected function getLocaleAliases($single = false): Collection
157157

158158
$inputs = explode(',', $input);
159159

160-
if (strpos($input, ':') === false && !$single) {
160+
if (strpos($input, ':') === false) {
161+
if ($single && count($inputs) == 1) {
162+
return collect([$single => $input]);
163+
}
164+
161165
$this->error('If publishing more than one locale, the aliases must be in the format "locale:alias,...".');
162166
exit;
163167
}
164-
elseif ($single && count($inputs) > 1 && (substr_count($input, ':') < count($inputs))) {
165-
$this->error('If publishing only one locale with a simple alias, only one alias should be passed.');
168+
elseif (substr_count($input, ':') < count($inputs)) {
169+
if ($single) {
170+
$this->error('If publishing only one locale with a simple alias, only one alias should be passed.');
171+
}
172+
else {
173+
$this->error('If publishing more than one locale, the aliases must be in the format "locale:alias,...".');
174+
}
166175
exit;
167176
}
168177

169-
foreach ($inputs as $alias) {
170-
@list($locale, $alias) = explode(':', $alias);
178+
foreach ($inputs as $input) {
179+
@list($locale, $alias) = explode(':', $input);
180+
181+
if (empty($alias) || empty($locale)) {
182+
$this->error(sprintf('Alias [%s] is not valid.', $input));
183+
exit;
184+
}
171185

172-
if (is_null($alias) && $single) {
173-
return collect([$single => $locale]);
186+
if ($aliases->has($locale)) {
187+
$this->warn(sprintf('Alias for [%s] locale was declared more than once and will be overwritten by the last value.', $locale));
174188
}
175189

176190
$aliases->put($locale, $alias);

0 commit comments

Comments
 (0)