From c6d9c2016cebe00bffb6e8cd49dfdd700b5b040d Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Sat, 22 Oct 2016 11:27:52 +0200 Subject: [PATCH] Make 'server' and 'storage' optional for 'auto' Resolves #35. Takes the value from the global config file as default argument. If it doesn't exist, but something in the config file exists, it takes that. If a command line argument is provided, it always takes precedence. --- src/Commands/Auto.php | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/Commands/Auto.php b/src/Commands/Auto.php index 9fc6803..e71bd0a 100644 --- a/src/Commands/Auto.php +++ b/src/Commands/Auto.php @@ -37,8 +37,6 @@ class Auto implements Command { * @return \Generator */ private function doExecute(Manager $args) { - $server = $args->get("server"); - $storage = $args->get("storage"); $configPath = $args->get("config"); try { @@ -55,6 +53,26 @@ class Auto implements Command { return; } + if ($args->exists("server")) { + $config["server"] = $args->get("server"); + } + + if ($args->exists("storage")) { + $config["storage"] = $args->get("storage"); + } + + if (!isset($config["server"])) { + $this->climate->error("Config file ({$configPath}) didn't have a 'server' set nor was it passed as command line argument."); + yield new CoroutineResult(self::EXIT_CONFIG_ERROR); + return; + } + + if (!isset($config["storage"])) { + $this->climate->error("Config file ({$configPath}) didn't have a 'storage' set nor was it passed as command line argument."); + yield new CoroutineResult(self::EXIT_CONFIG_ERROR); + return; + } + if (!isset($config["email"])) { $this->climate->error("Config file ({$configPath}) didn't have a 'email' set."); yield new CoroutineResult(self::EXIT_CONFIG_ERROR); @@ -72,9 +90,9 @@ class Auto implements Command { $GLOBALS["argv"][0], "setup", "--server", - $server, + $config["server"], "--storage", - $storage, + $config["storage"], "--email", $config["email"], ])); @@ -277,9 +295,15 @@ MESSAGE; } public static function getDefinition() { + $server = \Kelunik\AcmeClient\getArgumentDescription("server"); + $storage = \Kelunik\AcmeClient\getArgumentDescription("storage"); + + $server["required"] = false; + $storage["required"] = false; + $args = [ - "server" => \Kelunik\AcmeClient\getArgumentDescription("server"), - "storage" => \Kelunik\AcmeClient\getArgumentDescription("storage"), + "server" => $server, + "storage" => $storage, "config" => [ "prefix" => "c", "longPrefix" => "config",