Differential D18155 Diff 43701 src/applications/config/management/PhabricatorConfigManagementSetWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/config/management/PhabricatorConfigManagementSetWorkflow.php
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | if (empty($options[$key])) { | ||||
pht( | pht( | ||||
"No such configuration key '%s'! Use `%s` to list all keys.", | "No such configuration key '%s'! Use `%s` to list all keys.", | ||||
$key, | $key, | ||||
'config list')); | 'config list')); | ||||
} | } | ||||
$option = $options[$key]; | $option = $options[$key]; | ||||
$type = $option->newOptionType(); | |||||
if ($type) { | |||||
try { | |||||
$value = $type->newValueFromCommandLineValue( | |||||
$option, | |||||
$value); | |||||
} catch (PhabricatorConfigValidationException $ex) { | |||||
throw new PhutilArgumentUsageException($ex->getMessage()); | |||||
} | |||||
} else { | |||||
$type = $option->getType(); | $type = $option->getType(); | ||||
switch ($type) { | switch ($type) { | ||||
case 'string': | case 'string': | ||||
case 'class': | case 'class': | ||||
case 'enum': | case 'enum': | ||||
$value = (string)$value; | $value = (string)$value; | ||||
break; | break; | ||||
case 'int': | |||||
if (!ctype_digit($value)) { | |||||
throw new PhutilArgumentUsageException( | |||||
pht( | |||||
"Config key '%s' is of type '%s'. Specify an integer.", | |||||
$key, | |||||
$type)); | |||||
} | |||||
$value = (int)$value; | |||||
break; | |||||
case 'bool': | case 'bool': | ||||
if ($value == 'true') { | if ($value == 'true') { | ||||
$value = true; | $value = true; | ||||
} else if ($value == 'false') { | } else if ($value == 'false') { | ||||
$value = false; | $value = false; | ||||
} else { | } else { | ||||
throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
pht( | pht( | ||||
"Config key '%s' is of type '%s'. Specify '%s' or '%s'.", | "Config key '%s' is of type '%s'. Specify '%s' or '%s'.", | ||||
$key, | $key, | ||||
$type, | $type, | ||||
'true', | 'true', | ||||
'false')); | 'false')); | ||||
} | } | ||||
break; | break; | ||||
default: | default: | ||||
$value = json_decode($value, true); | $value = json_decode($value, true); | ||||
if (!is_array($value)) { | if (!is_array($value)) { | ||||
switch ($type) { | switch ($type) { | ||||
case 'set': | case 'set': | ||||
$command = csprintf( | $command = csprintf( | ||||
'./bin/config set %R %s', | './bin/config set %R %s', | ||||
$key, | $key, | ||||
'{"value1": true, "value2": true}'); | '{"value1": true, "value2": true}'); | ||||
$message = sprintf( | $message = sprintf( | ||||
"%s\n\n %s\n", | "%s\n\n %s\n", | ||||
pht( | pht( | ||||
'Config key "%s" is of type "%s". Specify it in JSON. '. | 'Config key "%s" is of type "%s". Specify it in JSON. '. | ||||
'For example:', | 'For example:', | ||||
$key, | $key, | ||||
$type), | $type), | ||||
$command); | $command); | ||||
break; | break; | ||||
default: | default: | ||||
if (preg_match('/^list</', $type)) { | if (preg_match('/^list</', $type)) { | ||||
$command = csprintf( | $command = csprintf( | ||||
'./bin/config set %R %s', | './bin/config set %R %s', | ||||
$key, | $key, | ||||
'["a", "b", "c"]'); | '["a", "b", "c"]'); | ||||
$message = sprintf( | $message = sprintf( | ||||
"%s\n\n %s\n", | "%s\n\n %s\n", | ||||
pht( | pht( | ||||
'Config key "%s" is of type "%s". Specify it in JSON. '. | 'Config key "%s" is of type "%s". Specify it in JSON. '. | ||||
'For example:', | 'For example:', | ||||
$key, | $key, | ||||
$type), | $type), | ||||
$command); | $command); | ||||
} else { | } else { | ||||
$message = pht( | $message = pht( | ||||
'Config key "%s" is of type "%s". Specify it in JSON.', | 'Config key "%s" is of type "%s". Specify it in JSON.', | ||||
$key, | $key, | ||||
$type); | $type); | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
throw new PhutilArgumentUsageException($message); | throw new PhutilArgumentUsageException($message); | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
} | |||||
$use_database = $args->getArg('database'); | $use_database = $args->getArg('database'); | ||||
if ($option->getLocked() && $use_database) { | if ($option->getLocked() && $use_database) { | ||||
throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
pht( | pht( | ||||
'Config key "%s" is locked and can only be set in local '. | 'Config key "%s" is locked and can only be set in local '. | ||||
'configuration. To learn more, see "%s" in the documentation.', | 'configuration. To learn more, see "%s" in the documentation.', | ||||
$key, | $key, | ||||
pht('Configuration Guide: Locked and Hidden Configuration'))); | pht('Configuration Guide: Locked and Hidden Configuration'))); | ||||
Show All 30 Lines |