diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 03923ffd..c78e0289 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -46,6 +46,7 @@ phutil_register_library_map(array( 'ArcanistExportWorkflow' => 'workflow/export', 'ArcanistFilenameLinter' => 'lint/linter/filename', 'ArcanistGeneratedLinter' => 'lint/linter/generated', + 'ArcanistGetConfigWorkflow' => 'workflow/get-config', 'ArcanistGitAPI' => 'repository/api/git', 'ArcanistGitHookPreReceiveWorkflow' => 'workflow/git-hook-pre-receive', 'ArcanistHelpWorkflow' => 'workflow/help', @@ -87,6 +88,7 @@ phutil_register_library_map(array( 'ArcanistPyFlakesLinter' => 'lint/linter/pyflakes', 'ArcanistPyLintLinter' => 'lint/linter/pylint', 'ArcanistRepositoryAPI' => 'repository/api/base', + 'ArcanistSetConfigWorkflow' => 'workflow/set-config', 'ArcanistShellCompleteWorkflow' => 'workflow/shell-complete', 'ArcanistSpellingDefaultData' => 'lint/linter/spelling', 'ArcanistSpellingLinter' => 'lint/linter/spelling', @@ -145,6 +147,7 @@ phutil_register_library_map(array( 'ArcanistExportWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistFilenameLinter' => 'ArcanistLinter', 'ArcanistGeneratedLinter' => 'ArcanistLinter', + 'ArcanistGetConfigWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistGitAPI' => 'ArcanistRepositoryAPI', 'ArcanistGitHookPreReceiveWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistHelpWorkflow' => 'ArcanistBaseWorkflow', @@ -170,6 +173,7 @@ phutil_register_library_map(array( 'ArcanistPhutilModuleLinter' => 'ArcanistLinter', 'ArcanistPyFlakesLinter' => 'ArcanistLinter', 'ArcanistPyLintLinter' => 'ArcanistLinter', + 'ArcanistSetConfigWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistShellCompleteWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistSpellingLinter' => 'ArcanistLinter', 'ArcanistSpellingLinterTestCase' => 'ArcanistLinterTestCase', diff --git a/src/workflow/base/ArcanistBaseWorkflow.php b/src/workflow/base/ArcanistBaseWorkflow.php index 03c9d7c8..77061c72 100644 --- a/src/workflow/base/ArcanistBaseWorkflow.php +++ b/src/workflow/base/ArcanistBaseWorkflow.php @@ -927,6 +927,16 @@ abstract class ArcanistBaseWorkflow { } } + protected function readGlobalArcConfig() { + return idx(self::readUserConfigurationFile(), 'config', array()); + } + + protected function writeGlobalArcConfig(array $options) { + $config = self::readUserConfigurationFile(); + $config['config'] = $options; + self::writeUserConfigurationFile($config); + } + /** * Write a message to stderr so that '--json' flags or stdout which is meant diff --git a/src/workflow/get-config/ArcanistGetConfigWorkflow.php b/src/workflow/get-config/ArcanistGetConfigWorkflow.php new file mode 100644 index 00000000..2dac758e --- /dev/null +++ b/src/workflow/get-config/ArcanistGetConfigWorkflow.php @@ -0,0 +1,66 @@ + 'argv', + ); + } + + public function run() { + $argv = $this->getArgument('argv'); + + $config = $this->readGlobalArcConfig(); + if ($argv) { + $keys = $argv; + } else { + $keys = array_keys($config); + sort($keys); + } + + foreach ($keys as $key) { + echo "{$key} = ".idx($config, $key)."\n"; + } + + return 0; + } + +} diff --git a/src/workflow/get-config/__init__.php b/src/workflow/get-config/__init__.php new file mode 100644 index 00000000..9e82bf6f --- /dev/null +++ b/src/workflow/get-config/__init__.php @@ -0,0 +1,15 @@ + 'argv', + ); + } + + public function run() { + $argv = $this->getArgument('argv'); + if (count($argv) != 2) { + throw new ArcanistUsageException("Specify a key and a value."); + } + + $config = $this->readGlobalArcConfig(); + + $key = $argv[0]; + $val = $argv[1]; + + $old = null; + if (array_key_exists($key, $config)) { + $old = $config[$key]; + } + + if (!strlen($val)) { + unset($config[$key]); + $this->writeGlobalArcConfig($config); + + if ($old === null) { + echo "Deleted key '{$key}'.\n"; + } else { + echo "Deleted key '{$key}' (was '{$old}').\n"; + } + } else { + $config[$key] = $val; + $this->writeGlobalArcConfig($config); + + if ($old === null) { + echo "Set key '{$key}' = '{$val}'.\n"; + } else { + echo "Set key '{$key}' = '{$val}' (was '{$old}').\n"; + } + } + + return 0; + } + +} diff --git a/src/workflow/set-config/__init__.php b/src/workflow/set-config/__init__.php new file mode 100644 index 00000000..a61965ae --- /dev/null +++ b/src/workflow/set-config/__init__.php @@ -0,0 +1,15 @@ +