From e5dad3f2d63668c8af90fcf92fe7abc699cfb36c Mon Sep 17 00:00:00 2001 From: Anthony Axenov Date: Mon, 8 Jul 2024 00:06:03 +0800 Subject: [PATCH] Fixed execution without params --- src/Environment.php | 3 +++ src/Processor.php | 14 +++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) 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..914102c 100644 --- a/src/Processor.php +++ b/src/Processor.php @@ -26,7 +26,7 @@ class Processor /** * Converter version */ - public const VERSION = '1.6.0'; + public const VERSION = '1.6.1'; /** * @var int Initial timestamp @@ -62,6 +62,8 @@ class Processor * Constructor * * @param array $argv Arguments came from cli + * @throws IncorrectSettingsFileException + * @throws JsonException */ public function __construct(protected readonly array $argv) { @@ -83,7 +85,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 +166,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'); }