Fix config file loader
This commit is contained in:
@@ -18,7 +18,8 @@
|
|||||||
"kelunik/certificate": "^1",
|
"kelunik/certificate": "^1",
|
||||||
"league/climate": "^3",
|
"league/climate": "^3",
|
||||||
"rdlowrey/auryn": "^1",
|
"rdlowrey/auryn": "^1",
|
||||||
"webmozart/assert": "^1"
|
"webmozart/assert": "^1",
|
||||||
|
"symfony/yaml": "^3.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^5",
|
"phpunit/phpunit": "^5",
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
namespace Kelunik\AcmeClient;
|
namespace Kelunik\AcmeClient;
|
||||||
|
|
||||||
|
use Kelunik\Acme\AcmeException;
|
||||||
use Phar;
|
use Phar;
|
||||||
|
use Symfony\Component\Yaml\Exception\ParseException;
|
||||||
|
use Symfony\Component\Yaml\Yaml;
|
||||||
use Webmozart\Assert\Assert;
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
function suggestCommand($badCommand, array $commands, $suggestThreshold = 70) {
|
function suggestCommand($badCommand, array $commands, $suggestThreshold = 70) {
|
||||||
@@ -74,15 +77,52 @@ function normalizePath($path) {
|
|||||||
function getArgumentDescription($argument) {
|
function getArgumentDescription($argument) {
|
||||||
$isPhar = \Kelunik\AcmeClient\isPhar();
|
$isPhar = \Kelunik\AcmeClient\isPhar();
|
||||||
|
|
||||||
|
$config = [];
|
||||||
|
|
||||||
|
if ($isPhar) {
|
||||||
|
$configPath = substr(dirname(Phar::running(true)), strlen("phar://")) . "/acme-client.yml";
|
||||||
|
|
||||||
|
if (file_exists($configPath)) {
|
||||||
|
$configContent = file_get_contents($configPath);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$value = Yaml::parse($configContent);
|
||||||
|
|
||||||
|
if (isset($value["server"]) && is_string($value["server"])) {
|
||||||
|
$config["server"] = $value["server"];
|
||||||
|
unset($value["server"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($value["storage"]) && is_string($value["storage"])) {
|
||||||
|
$config["storage"] = $value["storage"];
|
||||||
|
unset($value["storage"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($value)) {
|
||||||
|
throw new AcmeException("Provided YAML file had unknown options: " . implode(", ", array_keys($value)));
|
||||||
|
}
|
||||||
|
} catch (ParseException $e) {
|
||||||
|
throw new AcmeException("Unable to parse the YAML file ({$configPath}): " . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch ($argument) {
|
switch ($argument) {
|
||||||
case "server":
|
case "server":
|
||||||
return [
|
$argument = [
|
||||||
"prefix" => "s",
|
"prefix" => "s",
|
||||||
"longPrefix" => "server",
|
"longPrefix" => "server",
|
||||||
"description" => "ACME server to use for registration and issuance of certificates.",
|
"description" => "ACME server to use for registration and issuance of certificates.",
|
||||||
"required" => true,
|
"required" => true,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (isset($config["server"])) {
|
||||||
|
$argument["required"] = false;
|
||||||
|
$argument["defaultValue"] = $config["server"];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $argument;
|
||||||
|
|
||||||
case "storage":
|
case "storage":
|
||||||
$argument = [
|
$argument = [
|
||||||
"longPrefix" => "storage",
|
"longPrefix" => "storage",
|
||||||
@@ -92,6 +132,9 @@ function getArgumentDescription($argument) {
|
|||||||
|
|
||||||
if (!$isPhar) {
|
if (!$isPhar) {
|
||||||
$argument["defaultValue"] = dirname(__DIR__) . "/data";
|
$argument["defaultValue"] = dirname(__DIR__) . "/data";
|
||||||
|
} else if (isset($config["storage"])) {
|
||||||
|
$argument["required"] = false;
|
||||||
|
$argument["defaultValue"] = $config["storage"];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $argument;
|
return $argument;
|
||||||
|
|||||||
Reference in New Issue
Block a user