Browse Source

refactoring

master
Sven Ullmann 2 years ago
parent
commit
f41c91bb62
  1. 5
      src/commands/configure-plugin
  2. 5
      src/commands/install-plugin
  3. 5
      src/commands/list-projects
  4. 5
      src/commands/remove-project
  5. 21
      src/includes/configure-json-file.php

5
src/commands/configure-plugin

@ -18,8 +18,9 @@ source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/b
shortname=$(getArgument "$1" "shortname required" true)
plugin=$(getArgument "$2" "plugin required" true)
customer=$(getConfig false "project_manager.projects.$shortname.customer")
project=$(getConfig false "project_manager.projects.$shortname.project")
escapedShortname=${shortname//./\\.}
customer=$(getConfig false "project_manager.projects.$escapedShortname.customer")
project=$(getConfig false "project_manager.projects.$escapedShortname.project")
project_dir="$project_manager_dir/data/$customer/$project"
config_path="$project_dir/etc/$plugin/config.json"

5
src/commands/install-plugin

@ -18,8 +18,9 @@ source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/b
shortname=$(getArgument "$1" "shortname required" true)
plugin=$(getArgument "$2" "plugin required" true)
customer=$(getConfig false "project_manager.projects.$shortname.customer")
project=$(getConfig false "project_manager.projects.$shortname.project")
escapedShortname=${shortname//./\\.}
customer=$(getConfig false "project_manager.projects.$escapedShortname.customer")
project=$(getConfig false "project_manager.projects.$escapedShortname.project")
project_dir="$project_manager_dir/data/$customer/$project"
plugin_dir="$project_manager_dir/plugins/$plugin"
source="$project_manager_dir/plugins/$plugin/etc/config.json"

5
src/commands/list-projects

@ -24,8 +24,9 @@ function listProjects {
echo >&2
for shortname in "${projects[@]}"
do
customer="$(getConfig false "project_manager_dir.projects.$shortname.customer")"
project="$(getConfig false "project_manager_dir.projects.$shortname.project")"
escapedShortname=${shortname//./\\.}
customer="$(getConfig false "project_manager_dir.projects.$escapedShortname.customer")"
project="$(getConfig false "project_manager_dir.projects.$escapedShortname.project")"
echo "- Shortname: $shortname
Customer: $customer
Project: $project" >&2

5
src/commands/remove-project

@ -28,8 +28,9 @@ then
exit
fi
customer="$(getConfig false "project_manager.projects.$shortname.customer")"
project="$(getConfig false "project_manager.projects.$shortname.project")"
escapedShortname=${shortname//./\\.}
customer="$(getConfig false "project_manager.projects.$escapedShortname.customer")"
project="$(getConfig false "project_manager.projects.$escapedShortname.project")"
workspaces_dir="$(getConfig false "project_manager.workspaces_dir")"
workspace_dir="$workspaces_dir/$customer/$project"
project_dir="$project_manager_dir/data/$customer/$project"

21
src/includes/configure-json-file.php

@ -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));
Loading…
Cancel
Save