Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistSetConfigWorkflow.php
Show First 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | public function run() { | ||||
$key = $argv[0]; | $key = $argv[0]; | ||||
$val = $argv[1]; | $val = $argv[1]; | ||||
$settings = new ArcanistSettings(); | $settings = new ArcanistSettings(); | ||||
$console = PhutilConsole::getConsole(); | $console = PhutilConsole::getConsole(); | ||||
if (!$settings->getHelp($key)) { | if (!$settings->getHelp($key)) { | ||||
$warn = pht( | $warning = tsprintf( | ||||
'The configuration key \'%s\' is not recognized by arc. It may '. | "**%s:** %s\n", | ||||
pht('Warning'), | |||||
pht( | |||||
'The configuration key "%s" is not recognized by arc. It may '. | |||||
'be misspelled or out of date.', | 'be misspelled or out of date.', | ||||
$key); | $key)); | ||||
$console->writeErr("**%s:** %s\n", pht('Warning'), $warn); | $console->writeErr('%s', $warning); | ||||
} | } | ||||
$old = null; | $old = null; | ||||
if (array_key_exists($key, $config)) { | if (array_key_exists($key, $config)) { | ||||
$old = $config[$key]; | $old = $config[$key]; | ||||
} | } | ||||
if (!strlen($val)) { | if (!strlen($val)) { | ||||
unset($config[$key]); | unset($config[$key]); | ||||
if ($is_local) { | if ($is_local) { | ||||
$configuration_manager->writeLocalArcConfig($config); | $configuration_manager->writeLocalArcConfig($config); | ||||
} else { | } else { | ||||
$configuration_manager->writeUserArcConfig($config); | $configuration_manager->writeUserArcConfig($config); | ||||
} | } | ||||
$old = $settings->formatConfigValueForDisplay($key, $old); | $old = $settings->formatConfigValueForDisplay($key, $old); | ||||
if ($old === null) { | if ($old === null) { | ||||
$console->writeOut( | $message = pht( | ||||
"Deleted key '%s' from %s config.\n", | 'Deleted key "%s" from %s config.', | ||||
$key, | $key, | ||||
$which); | $which); | ||||
} else { | } else { | ||||
$console->writeOut( | $message = pht( | ||||
"Deleted key '%s' from %s config (was %s).\n", | 'Deleted key "%s" from %s config (was %s).', | ||||
$key, | $key, | ||||
$which, | $which, | ||||
$old); | $old); | ||||
} | } | ||||
$console->writeOut('%s', tsprintf("%s\n", $message)); | |||||
} else { | } else { | ||||
$val = $settings->willWriteValue($key, $val); | $val = $settings->willWriteValue($key, $val); | ||||
$config[$key] = $val; | $config[$key] = $val; | ||||
if ($is_local) { | if ($is_local) { | ||||
$configuration_manager->writeLocalArcConfig($config); | $configuration_manager->writeLocalArcConfig($config); | ||||
} else { | } else { | ||||
$configuration_manager->writeUserArcConfig($config); | $configuration_manager->writeUserArcConfig($config); | ||||
} | } | ||||
$val = $settings->formatConfigValueForDisplay($key, $val); | $val = $settings->formatConfigValueForDisplay($key, $val); | ||||
$old = $settings->formatConfigValueForDisplay($key, $old); | $old = $settings->formatConfigValueForDisplay($key, $old); | ||||
if ($old === null) { | if ($old === null) { | ||||
$console->writeOut( | $message = pht( | ||||
"Set key '%s' = %s in %s config.\n", | 'Set key "%s" = %s in %s config.', | ||||
$key, | $key, | ||||
$val, | $val, | ||||
$which); | $which); | ||||
} else { | } else { | ||||
$console->writeOut( | $message = pht( | ||||
"Set key '%s' = %s in %s config (was %s).\n", | 'Set key "%s" = %s in %s config (was %s).', | ||||
$key, | $key, | ||||
$val, | $val, | ||||
$which, | $which, | ||||
$old); | $old); | ||||
} | } | ||||
$console->writeOut('%s', tsprintf("%s\n", $message)); | |||||
} | } | ||||
return 0; | return 0; | ||||
} | } | ||||
} | } |