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 pht("Deleted key '%s' from %s config.\n", $key, $which);
         } else {
             echo pht("Deleted key '%s' from %s config (was %s).\n", $key, $which, $old);
         }
     } 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 pht("Set key '%s' = %s in %s config.\n", $key, $val, $which);
         } else {
             echo pht("Set key '%s' = %s in %s config (was %s).\n", $key, $val, $which, $old);
         }
     }
     return 0;
 }
 public function run()
 {
     $argv = $this->getArgument('argv');
     $settings = new ArcanistSettings();
     $configs = array('system' => self::readSystemArcConfig(), 'global' => self::readGlobalArcConfig(), 'project' => $this->getWorkingCopy()->getProjectConfig(), 'local' => $this->readLocalArcConfig());
     if ($argv) {
         $keys = $argv;
     } else {
         $keys = array_mergev(array_map('array_keys', $configs));
         $keys = array_unique($keys);
         sort($keys);
     }
     $multi = count($keys) > 1;
     foreach ($keys as $key) {
         if ($multi) {
             echo "{$key}\n";
         }
         foreach ($configs as $name => $config) {
             switch ($name) {
                 case 'project':
                     // Respect older names in project config.
                     $val = $this->getWorkingCopy()->getConfig($key);
                     break;
                 default:
                     $val = idx($config, $key);
                     break;
             }
             if ($val === null) {
                 continue;
             }
             $val = $settings->formatConfigValueForDisplay($key, $val);
             printf("% 10.10s: %s\n", $name, $val);
         }
         if ($multi) {
             echo "\n";
         }
     }
     return 0;
 }
 /**
  * Read a configuration directive from project configuration. This reads ONLY
  * permanent project configuration (i.e., ".arcconfig"), not other
  * configuration sources. See @{method:getConfigFromAnySource} to read from
  * user configuration.
  *
  * @param key   Key to read.
  * @param wild  Default value if key is not found.
  * @return wild Value, or default value if not found.
  *
  * @task config
  */
 public function getProjectConfig($key, $default = null)
 {
     $settings = new ArcanistSettings();
     $pval = idx($this->projectConfig, $key);
     // Test for older names in the per-project config only, since
     // they've only been used there.
     if ($pval === null) {
         $legacy = $settings->getLegacyName($key);
         if ($legacy) {
             $pval = $this->getProjectConfig($legacy);
         }
     }
     if ($pval === null) {
         $pval = $default;
     } else {
         $pval = $settings->willReadValue($key, $pval);
     }
     return $pval;
 }
 public function run()
 {
     $argv = $this->getArgument('argv');
     $verbose = $this->getArgument('verbose');
     $settings = new ArcanistSettings();
     $configuration_manager = $this->getConfigurationManager();
     $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) {
         $keys = $argv;
     } else {
         $keys = array_mergev(array_map('array_keys', $configs));
         $keys = array_merge($keys, $settings->getAllKeys());
         $keys = array_unique($keys);
         sort($keys);
     }
     $console = PhutilConsole::getConsole();
     $multi = count($keys) > 1;
     foreach ($keys as $key) {
         $console->writeOut("**%s**\n\n", $key);
         if ($verbose) {
             $help = $settings->getHelp($key);
             if (!$help) {
                 $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));
             $console->writeOut("%s: %s\n\n", sprintf('% 20.20s', pht('Example Value')), $settings->getExample($key));
         }
         $values = array();
         foreach ($configs as $config_key => $config) {
             if (array_key_exists($key, $config)) {
                 $values[$config_key] = $config[$key];
             } else {
                 // If we didn't find a value, look for a legacy value.
                 $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('%s: ', sprintf('% 20.20s', pht('Current Value')));
         if ($values) {
             $value = head($values);
             $value = $settings->formatConfigValueForDisplay($key, $value);
             $console->writeOut("%s\n", $value);
         } else {
             $console->writeOut("-\n");
         }
         $console->writeOut('%s: ', sprintf('% 20.20s', pht('Current Source')));
         if ($values) {
             $source = head_key($values);
             $console->writeOut("%s\n", $source);
         } else {
             $console->writeOut("-\n");
         }
         if ($verbose) {
             $console->writeOut("\n");
             foreach ($configs as $name => $config) {
                 $have_value = false;
                 if (array_key_exists($name, $values)) {
                     $have_value = true;
                     $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 "\n";
         }
     }
     if (!$verbose) {
         $console->writeOut("%s\n", pht('(Run with --verbose for more details.)'));
     }
     return 0;
 }
 public function readDefaultConfig()
 {
     $settings = new ArcanistSettings();
     return $settings->getDefaultSettings();
 }
 private function show()
 {
     $config = self::readGlobalArcConfig();
     $settings = new ArcanistSettings();
     $keys = $settings->getAllKeys();
     sort($keys);
     foreach ($keys as $key) {
         $type = $settings->getType($key);
         $example = $settings->getExample($key);
         $help = $settings->getHelp($key);
         $value = idx($config, $key);
         $value = $settings->formatConfigValueForDisplay($key, $value);
         echo phutil_console_format("**__%s__** (%s)\n\n", $key, $type);
         if ($example !== null) {
             echo phutil_console_format("           Example: %s\n", $example);
         }
         if (strlen($value)) {
             echo phutil_console_format("    Global Setting: %s\n", $value);
         }
         echo "\n";
         echo phutil_console_wrap($help, 4);
         echo "\n\n\n";
     }
     return 0;
 }
 /**
  * Read a configuration directive from any available configuration source.
  * In contrast to @{method:getConfig}, this will look for the directive in
  * local and user configuration in addition to project configuration.
  * The precedence is local > project > user
  *
  * @param key   Key to read.
  * @param wild  Default value if key is not found.
  * @return wild Value, or default value if not found.
  *
  * @task config
  */
 public function getConfigFromAnySource($key, $default = null)
 {
     $settings = new ArcanistSettings();
     // try runtime config first
     $pval = idx($this->runtimeConfig, $key);
     // try local config
     if ($pval === null) {
         $pval = $this->getLocalConfig($key);
     }
     // then per-project config
     if ($pval === null) {
         $pval = $this->getConfig($key);
     }
     // now try global (i.e. user-level) config
     if ($pval === null) {
         $global_config = ArcanistBaseWorkflow::readGlobalArcConfig();
         $pval = idx($global_config, $key);
     }
     // Finally, try system-level config.
     if ($pval === null) {
         $system_config = ArcanistBaseWorkflow::readSystemArcConfig();
         $pval = idx($system_config, $key);
     }
     if ($pval === null) {
         $pval = $default;
     } else {
         $pval = $settings->willReadValue($key, $pval);
     }
     return $pval;
 }