Fixed execution without params

This commit is contained in:
Anthony Axenov 2024-07-08 00:06:03 +08:00
parent 47930b010f
commit 2fd60a33bd
Signed by: anthony
GPG Key ID: EA9EC32FF7CCD4EC
2 changed files with 11 additions and 2 deletions

View File

@ -44,6 +44,9 @@ class Environment implements ArrayAccess
*/
public function readFromFile(string $filepath): static
{
if (empty($filepath)) {
return $this;
}
$content = file_get_contents(static::$filepath = $filepath);
$content = json_decode($content, flags: JSON_THROW_ON_ERROR); //TODO try-catch
$content || throw new JsonException("not a valid environment: $filepath");

View File

@ -83,7 +83,9 @@ class Processor
*/
protected function parseArgs(): void
{
foreach ($this->argv as $idx => $arg) {
$arguments = array_slice($this->argv, 1);
$needHelp = count($arguments) === 0 && !$this->settings::fileExists();
foreach ($arguments as $idx => $arg) {
switch ($arg) {
case '-f':
case '--file':
@ -162,9 +164,13 @@ class Processor
case '-h':
case '--help':
die(implode(EOL, $this->usage()) . EOL);
$needHelp = true;
break;
}
}
if ($needHelp) {
die(implode(EOL, $this->usage()) . EOL);
}
if (empty($this->settings->collectionPaths())) {
throw new InvalidArgumentException('there are no collections to convert');
}