Changeset View
Changeset View
Standalone View
Standalone View
src/toolset/workflow/ArcanistGetConfigWorkflow.php
Context not available. | |||||
public function runWorkflow() { | public function runWorkflow() { | ||||
$argv = $this->getArgument('argv'); | $argv = $this->getArgument('argv'); | ||||
$verbose = $this->getArgument('verbose'); | $is_verbose = $this->getArgument('verbose'); | ||||
$configuration_list = $this->getConfigurationSourceList(); | |||||
$configs = array( | |||||
ArcanistConfigurationManager::CONFIG_SOURCE_LOCAL => | |||||
$configuration_manager->readLocalArcConfig(), | |||||
ArcanistConfigurationManager::CONFIG_SOURCE_PROJECT => | |||||
$this->getWorkingCopy()->readProjectConfig(), | |||||
ArcanistConfigurationManager::CONFIG_SOURCE_USER => | |||||
$configuration_manager->readUserArcConfig(), | |||||
ArcanistConfigurationManager::CONFIG_SOURCE_SYSTEM => | |||||
$configuration_manager->readSystemArcConfig(), | |||||
ArcanistConfigurationManager::CONFIG_SOURCE_DEFAULT => | |||||
$configuration_manager->readDefaultConfig(), | |||||
); | |||||
if ($argv) { | $source_list = $this->getConfigurationSourceList(); | ||||
$keys = $argv; | $config_engine = $this->getConfigurationEngine(); | ||||
} else { | |||||
$keys = array_mergev(array_map('array_keys', $configs)); | |||||
$keys = array_merge($keys, $settings->getAllKeys()); | |||||
$keys = array_unique($keys); | |||||
sort($keys); | |||||
} | |||||
$console = PhutilConsole::getConsole(); | $options_map = $config_engine->newConfigOptionsMap(); | ||||
$multi = (count($keys) > 1); | |||||
foreach ($keys as $key) { | $all_keys = array(); | ||||
$console->writeOut("**%s**\n\n", $key); | $alias_map = array(); | ||||
foreach ($options_map as $key => $config_option) { | |||||
$all_keys[$key] = $key; | |||||
foreach ($config_option->getAliases() as $alias) { | |||||
$alias_map[$alias] = $key; | |||||
} | |||||
} | |||||
if ($verbose) { | foreach ($source_list->getSources() as $source) { | ||||
$help = $settings->getHelp($key); | foreach ($source->getAllKeys() as $key) { | ||||
if (!$help) { | $all_keys[$key] = $key; | ||||
$help = pht( | } | ||||
'(This configuration value is not recognized by arc. It may '. | } | ||||
'be misspelled or out of date.)'); | |||||
} | |||||
$console->writeOut("%s\n\n", phutil_console_wrap($help, 4)); | ksort($all_keys); | ||||
$console->writeOut( | $defaults_map = $config_engine->newDefaults(); | ||||
"%s: %s\n\n", | |||||
sprintf('% 20.20s', pht('Example Value')), | |||||
$settings->getExample($key)); | |||||
} | foreach ($all_keys as $key) { | ||||
$option = idx($options_map, $key); | |||||
$values = array(); | if ($option) { | ||||
foreach ($configs as $config_key => $config) { | $option_summary = $option->getSummary(); | ||||
if (array_key_exists($key, $config)) { | $option_help = $option->getHelp(); | ||||
$values[$config_key] = $config[$key]; | } else { | ||||
} else { | $option_summary = pht('(This option is unrecognized.)'); | ||||
// If we didn't find a value, look for a legacy value. | $option_help = $option_summary; | ||||
$source_project = ArcanistConfigurationManager::CONFIG_SOURCE_PROJECT; | |||||
if ($config_key === $source_project) { | |||||
$legacy_name = $settings->getLegacyName($key); | |||||
if (array_key_exists($legacy_name, $config)) { | |||||
$values[$config_key] = $config[$legacy_name]; | |||||
} | |||||
} | |||||
} | |||||
} | } | ||||
$console->writeOut( | if ($option) { | ||||
'%s: ', | $formatter = $option; | ||||
sprintf('% 20.20s', pht('Current Value'))); | } else { | ||||
$formatter = new ArcanistWildConfigOption(); | |||||
} | |||||
if ($values) { | if (!$is_verbose) { | ||||
$value = head($values); | echo tsprintf( | ||||
$value = $settings->formatConfigValueForDisplay($key, $value); | "**%s**\n%R\n\n", | ||||
$console->writeOut("%s\n", $value); | $key, | ||||
$option_summary); | |||||
} else { | } else { | ||||
$console->writeOut("-\n"); | echo tsprintf( | ||||
"**%s**\n\n%R\n\n", | |||||
$key, | |||||
$option_help); | |||||
} | } | ||||
$console->writeOut( | // NOTE: We can only get configuration from a SourceList if the option is | ||||
'%s: ', | // a recognized option, so skip this part if the option isn't known. | ||||
sprintf('% 20.20s', pht('Current Source'))); | if ($option) { | ||||
$value = $source_list->getConfig($key); | |||||
$display_value = $formatter->getDisplayValueFromValue($value); | |||||
if ($values) { | echo tsprintf("%s: %s\n", pht('Value'), $display_value); | ||||
$source = head_key($values); | |||||
$console->writeOut("%s\n", $source); | $default_value = idx($defaults_map, $key); | ||||
} else { | $display_default = $formatter->getDisplayValueFromValue($value); | ||||
$console->writeOut("-\n"); | |||||
echo tsprintf("%s: %s\n", pht('Default'), $display_default); | |||||
} | } | ||||
if ($verbose) { | foreach ($source_list->getSources() as $source) { | ||||
$console->writeOut("\n"); | if ($source->hasValueForKey($key)) { | ||||
$source_value = $source->getValueForKey($key); | |||||
foreach ($configs as $name => $config) { | $source_value = $formatter->getValueFromStorageValue($source_value); | ||||
$have_value = false; | $source_display = $formatter->getDisplayValueFromValue($source_value); | ||||
if (array_key_exists($name, $values)) { | } else { | ||||
$have_value = true; | $source_display = pht('-'); | ||||
$value = $values[$name]; | |||||
} | |||||
$console->writeOut( | |||||
'%s: ', | |||||
sprintf('% 20.20s', pht('%s Value', $name))); | |||||
if ($have_value) { | |||||
$console->writeOut( | |||||
"%s\n", | |||||
$settings->formatConfigValueForDisplay($key, $value)); | |||||
} else { | |||||
$console->writeOut("-\n"); | |||||
} | |||||
} | } | ||||
} | |||||
if ($multi) { | echo tsprintf( | ||||
echo "\n"; | "%s: %s\n", | ||||
$source->getSourceDisplayName(), | |||||
$source_display); | |||||
} | } | ||||
} | } | ||||
if (!$verbose) { | // if (!$verbose) { | ||||
$console->writeOut( | // $console->writeOut( | ||||
"(%s)\n", | // "(%s)\n", | ||||
pht('Run with %s for more details.', '--verbose')); | // pht('Run with %s for more details.', '--verbose')); | ||||
} | // } | ||||
amckinley: We can make this work now just by switching to `$is_verbose` and `echo tsprintf()`, right? | |||||
epriestleyAuthorUnsubmitted Done Inline ActionsI think I want to drop "verbose" mode and do this instead to simplify things a bit:
But I kind of waffled on this and ended up with the flag still existing and this bit commented out. I'd anticipate cleaning it up in the next pass. epriestley: I think I want to drop "verbose" mode and do this instead to simplify things a bit:
- `arc get… | |||||
return 0; | return 0; | ||||
} | } | ||||
Context not available. |
We can make this work now just by switching to $is_verbose and echo tsprintf(), right?