diff --git a/src/Environment.php b/src/Environment.php index 3fe8bf8..fae7b92 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -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"); diff --git a/src/Processor.php b/src/Processor.php index 73d57d7..39315a5 100644 --- a/src/Processor.php +++ b/src/Processor.php @@ -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'); }