1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +01:00

Improve error messages when specifying bad set or list to bin/config

Summary: Fixes T7308. Multiple users have encountered confusion around how they should specify a set or list in JSON; provide examples.

Test Plan:
```
epriestley@orbital ~/dev/phabricator $ ./bin/config set files.image-mime-types true
Usage Exception: Config key 'files.image-mime-types' is of type 'set'. Specify it in JSON. For example:

    ./bin/config set '{"value1": true, "value2": true}'

epriestley@orbital ~/dev/phabricator $ ./bin/config set cluster.addresses true
Usage Exception: Config key 'cluster.addresses' is of type 'list<string>'. Specify it in JSON. For example:

    ./bin/config set '["a", "b", "c"]'

epriestley@orbital ~/dev/phabricator $
```

Reviewers: btrahan, chad

Reviewed By: chad

Subscribers: epriestley

Maniphest Tasks: T7308

Differential Revision: https://secure.phabricator.com/D11925
This commit is contained in:
epriestley 2015-03-02 07:51:19 -08:00
parent 2387c1e918
commit d69a6b8490

View file

@ -87,10 +87,34 @@ final class PhabricatorConfigManagementSetWorkflow
default:
$value = json_decode($value, true);
if (!is_array($value)) {
throw new PhutilArgumentUsageException(pht(
"Config key '%s' is of type '%s'. Specify it in JSON.",
$key,
$type));
switch ($type) {
case 'set':
$message = pht(
"Config key '%s' is of type '%s'. Specify it in JSON. ".
"For example:\n\n".
' ./bin/config set \'{"value1": true, "value2": true}\''.
"\n",
$key,
$type);
break;
default:
if (preg_match('/^list</', $type)) {
$message = pht(
"Config key '%s' is of type '%s'. Specify it in JSON. ".
"For example:\n\n".
' ./bin/config set \'["a", "b", "c"]\''.
"\n",
$key,
$type);
} else {
$message = pht(
'Config key "%s" is of type "%s". Specify it in JSON.',
$key,
$type);
}
break;
}
throw new PhutilArgumentUsageException($message);
}
break;
}