mirror of
https://we.phorge.it/source/arcanist.git
synced 2025-01-10 14:51:05 +01:00
104219dd62
Summary: Fixes T4952. Several issues: - You review configuration values with `arc set-config --show`. This makes no sense and never has, I think it just predated `arc get-config` or was easier or something. - Instead, review values with `arc get-config` and review details with `arc get-config --verbose`. - Show better and more detailed information about all config sources. - Establish and show default values from a new "default" source. - With `--trace` include more information about attempts to read configuration files. Test Plan: Ran `arc get-config --trace --verbose` in various working directories and received sensible-looking output. {F156247} Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4952 Differential Revision: https://secure.phabricator.com/D9172
115 lines
3 KiB
PHP
115 lines
3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Write configuration settings.
|
|
*/
|
|
final class ArcanistSetConfigWorkflow extends ArcanistBaseWorkflow {
|
|
|
|
public function getWorkflowName() {
|
|
return 'set-config';
|
|
}
|
|
|
|
public function getCommandSynopses() {
|
|
return phutil_console_format(<<<EOTEXT
|
|
**set-config** [__options__] -- __name__ __value__
|
|
EOTEXT
|
|
);
|
|
}
|
|
|
|
public function getCommandHelp() {
|
|
return phutil_console_format(<<<EOTEXT
|
|
Supports: cli
|
|
Sets an arc configuration option.
|
|
|
|
Options are either user (apply to all arc commands you invoke
|
|
from the current user) or local (apply only to the current working
|
|
copy). By default, user configuration is written. Use __--local__
|
|
to write local configuration.
|
|
|
|
User values are written to '~/.arcrc' on Linux and Mac OS X, and an
|
|
undisclosed location on Windows. Local values are written to an arc
|
|
directory under either .git, .hg, or .svn as appropriate.
|
|
EOTEXT
|
|
);
|
|
}
|
|
|
|
public function getArguments() {
|
|
return array(
|
|
'local' => array(
|
|
'help' => 'Set a local config value instead of a user one',
|
|
),
|
|
'*' => 'argv',
|
|
);
|
|
}
|
|
|
|
public function requiresRepositoryAPI() {
|
|
return $this->getArgument('local');
|
|
}
|
|
|
|
public function run() {
|
|
$argv = $this->getArgument('argv');
|
|
if (count($argv) != 2) {
|
|
throw new ArcanistUsageException(
|
|
pht('Specify a key and a value.'));
|
|
}
|
|
$configuration_manager = $this->getConfigurationManager();
|
|
|
|
$is_local = $this->getArgument('local');
|
|
|
|
if ($is_local) {
|
|
$config = $configuration_manager->readLocalArcConfig();
|
|
$which = 'local';
|
|
} else {
|
|
$config = $configuration_manager->readUserArcConfig();
|
|
$which = 'user';
|
|
}
|
|
|
|
$key = $argv[0];
|
|
$val = $argv[1];
|
|
|
|
$settings = new ArcanistSettings();
|
|
|
|
$old = null;
|
|
if (array_key_exists($key, $config)) {
|
|
$old = $config[$key];
|
|
}
|
|
|
|
if (!strlen($val)) {
|
|
unset($config[$key]);
|
|
if ($is_local) {
|
|
$configuration_manager->writeLocalArcConfig($config);
|
|
} else {
|
|
$configuration_manager->writeUserArcConfig($config);
|
|
}
|
|
|
|
$old = $settings->formatConfigValueForDisplay($key, $old);
|
|
|
|
if ($old === null) {
|
|
echo "Deleted key '{$key}' from {$which} config.\n";
|
|
} else {
|
|
echo "Deleted key '{$key}' from {$which} config (was {$old}).\n";
|
|
}
|
|
} else {
|
|
$val = $settings->willWriteValue($key, $val);
|
|
|
|
$config[$key] = $val;
|
|
if ($is_local) {
|
|
$configuration_manager->writeLocalArcConfig($config);
|
|
} else {
|
|
$configuration_manager->writeUserArcConfig($config);
|
|
}
|
|
|
|
$val = $settings->formatConfigValueForDisplay($key, $val);
|
|
$old = $settings->formatConfigValueForDisplay($key, $old);
|
|
|
|
if ($old === null) {
|
|
echo "Set key '{$key}' = {$val} in {$which} config.\n";
|
|
} else {
|
|
echo "Set key '{$key}' = {$val} in {$which} config (was {$old}).\n";
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
}
|