Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / config / management / PhabricatorConfigManagementGetWorkflow.php
blob800ffe594229da635dba4eb91560bd8088a51b9a
1 <?php
3 final class PhabricatorConfigManagementGetWorkflow
4 extends PhabricatorConfigManagementWorkflow {
6 protected function didConstruct() {
7 $this
8 ->setName('get')
9 ->setExamples('**get** __key__')
10 ->setSynopsis(pht('Get a local configuration value.'))
11 ->setArguments(
12 array(
13 array(
14 'name' => 'args',
15 'wildcard' => true,
17 ));
20 public function execute(PhutilArgumentParser $args) {
21 $console = PhutilConsole::getConsole();
23 $argv = $args->getArg('args');
24 if (count($argv) == 0) {
25 throw new PhutilArgumentUsageException(
26 pht('Specify a configuration key to get.'));
29 $key = $argv[0];
31 if (count($argv) > 1) {
32 throw new PhutilArgumentUsageException(
33 pht('Too many arguments: expected one key.'));
36 $options = PhabricatorApplicationConfigOptions::loadAllOptions();
37 if (empty($options[$key])) {
38 throw new PhutilArgumentUsageException(
39 pht(
40 "No such configuration key '%s'! Use `%s` to list all keys.",
41 $key,
42 'config list'));
45 $values = array();
46 $config = new PhabricatorConfigLocalSource();
47 $local_value = $config->getKeys(array($key));
48 if (empty($local_value)) {
49 $values['local'] = array(
50 'key' => $key,
51 'value' => null,
52 'status' => 'unset',
53 'errorInfo' => null,
55 } else {
56 $values['local'] = array(
57 'key' => $key,
58 'value' => reset($local_value),
59 'status' => 'set',
60 'errorInfo' => null,
64 try {
65 $database_config = new PhabricatorConfigDatabaseSource('default');
66 $database_value = $database_config->getKeys(array($key));
67 if (empty($database_value)) {
68 $values['database'] = array(
69 'key' => $key,
70 'value' => null,
71 'status' => 'unset',
72 'errorInfo' => null,
74 } else {
75 $values['database'] = array(
76 'key' => $key,
77 'value' => reset($database_value),
78 'status' => 'set',
79 'errorInfo' => null,
82 } catch (Exception $e) {
83 $values['database'] = array(
84 'key' => $key,
85 'value' => null,
86 'status' => 'error',
87 'errorInfo' => pht('Database source is not configured properly'),
91 $result = array();
92 foreach ($values as $source => $value) {
93 $result[] = array(
94 'key' => $value['key'],
95 'source' => $source,
96 'value' => $value['value'],
97 'status' => $value['status'],
98 'errorInfo' => $value['errorInfo'],
101 $result = array(
102 'config' => $result,
105 $json = new PhutilJSON();
106 $console->writeOut($json->encodeFormatted($result));