|
|
@ -7,19 +7,28 @@ $configuration = []; |
|
|
|
$jsonFile = $_SERVER['argv'][1]; |
|
|
|
$configuration = json_decode(file_get_contents($jsonFile), true); |
|
|
|
|
|
|
|
function readNext($config, &$current) { |
|
|
|
function readNext($config, &$current, $keyPath = '') { |
|
|
|
foreach ($config as $key => $value) { |
|
|
|
if (is_array($value) && !isset($value[0])) { |
|
|
|
readNext($value, $current[$key]); |
|
|
|
readNext($value, $current[$key], "$keyPath.$key"); |
|
|
|
} else { |
|
|
|
$prompt = "$key [default:$value]"; |
|
|
|
$current[$key] = readline($prompt); |
|
|
|
$default = $value; |
|
|
|
if (is_bool($value)) { |
|
|
|
$default = true === $value ? 'true' : 'false'; |
|
|
|
} |
|
|
|
if (null === $value) { |
|
|
|
$default = null; |
|
|
|
} |
|
|
|
$prompt = "$keyPath.$key: " . ($default !== null ? "[$default]": ""); |
|
|
|
$ret = readline($prompt); |
|
|
|
$current[$key] = "" === $ret ? ($value === null ? null : $default) : $ret; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
foreach ($configuration as $key => $config) { |
|
|
|
readNext($config, $configuration[$key]); |
|
|
|
readNext($config, $configuration[$key], $key); |
|
|
|
} |
|
|
|
|
|
|
|
file_put_contents($jsonFile, json_encode($configuration, JSON_PRETTY_PRINT && JSON_ERROR_NONE && JSON_UNESCAPED_SLASHES)); |
|
|
|
file_put_contents($jsonFile, json_encode($configuration, |
|
|
|
JSON_PRETTY_PRINT | JSON_ERROR_NONE | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT)); |