public function buildAllWorkflows() { $workflows = parent::buildAllWorkflows(); // We dont use SVN unset($workflows['svn-hook-pre-commit']); return $workflows; }
private function assertArgumentCompletion($expect, $input, $arguments) { $result = ArcanistConfiguration::correctArgumentSpelling($input, $arguments); sort($result); sort($expect); $arguments = implode(', ', $arguments); $this->assertEqual($expect, $result, "Correction of {$input} against: {$arguments}"); }
public static function resolveAliases($command, ArcanistConfiguration $config, array $argv, ArcanistConfigurationManager $configuration_manager) { $aliases = self::getAliases($configuration_manager); if (!isset($aliases[$command])) { return array(null, $argv); } $new_command = head($aliases[$command]); if (self::isShellCommandAlias($new_command)) { return array($new_command, $argv); } $workflow = $config->buildWorkflow($new_command); if (!$workflow) { return array(null, $argv); } $alias_argv = array_slice($aliases[$command], 1); foreach (array_reverse($alias_argv) as $alias_arg) { if (!in_array($alias_arg, $argv)) { array_unshift($argv, $alias_arg); } } return array($new_command, $argv); }
public function parseArguments(array $args) { $this->passedArguments = $args; $spec = $this->getCompleteArgumentSpecification(); $dict = array(); $more_key = null; if (!empty($spec['*'])) { $more_key = $spec['*']; unset($spec['*']); $dict[$more_key] = array(); } $short_to_long_map = array(); foreach ($spec as $long => $options) { if (!empty($options['short'])) { $short_to_long_map[$options['short']] = $long; } } foreach ($spec as $long => $options) { if (!empty($options['repeat'])) { $dict[$long] = array(); } } $more = array(); for ($ii = 0; $ii < count($args); $ii++) { $arg = $args[$ii]; $arg_name = null; $arg_key = null; if ($arg == '--') { $more = array_merge($more, array_slice($args, $ii + 1)); break; } else { if (!strncmp($arg, '--', 2)) { $arg_key = substr($arg, 2); if (!array_key_exists($arg_key, $spec)) { $corrected = ArcanistConfiguration::correctArgumentSpelling($arg_key, array_keys($spec)); if (count($corrected) == 1) { PhutilConsole::getConsole()->writeErr(pht("(Assuming '%s' is the British spelling of '%s'.)", '--' . $arg_key, '--' . head($corrected)) . "\n"); $arg_key = head($corrected); } else { throw new ArcanistUsageException("Unknown argument '{$arg_key}'. Try 'arc help'."); } } } else { if (!strncmp($arg, '-', 1)) { $arg_key = substr($arg, 1); if (empty($short_to_long_map[$arg_key])) { throw new ArcanistUsageException("Unknown argument '{$arg_key}'. Try 'arc help'."); } $arg_key = $short_to_long_map[$arg_key]; } else { $more[] = $arg; continue; } } } $options = $spec[$arg_key]; if (empty($options['param'])) { $dict[$arg_key] = true; } else { if ($ii == count($args) - 1) { throw new ArcanistUsageException("Option '{$arg}' requires a parameter."); } if (!empty($options['repeat'])) { $dict[$arg_key][] = $args[$ii + 1]; } else { $dict[$arg_key] = $args[$ii + 1]; } $ii++; } } if ($more) { if ($more_key) { $dict[$more_key] = $more; } else { $example = reset($more); throw new ArcanistUsageException("Unrecognized argument '{$example}'. Try 'arc help'."); } } foreach ($dict as $key => $value) { if (empty($spec[$key]['conflicts'])) { continue; } foreach ($spec[$key]['conflicts'] as $conflict => $more) { if (isset($dict[$conflict])) { if ($more) { $more = ': ' . $more; } else { $more = '.'; } // TODO: We'll always display these as long-form, when the user might // have typed them as short form. throw new ArcanistUsageException("Arguments '--{$key}' and '--{$conflict}' are mutually exclusive" . $more); } } } $this->arguments = $dict; $this->didParseArguments(); return $this; }
arcanist_load_libraries(idx($system_config, 'load', array()), $must_load = true, $lib_source = 'the "load" setting in system config', $working_copy); // Load libraries in global 'load' config, as per "arc set-config load". We // need to fail softly if these break because errors would prevent the user // from running "arc set-config" to correct them. arcanist_load_libraries(idx($global_config, 'load', array()), $must_load = false, $lib_source = 'the "load" setting in global config', $working_copy); // Load libraries in ".arcconfig". Libraries here must load. arcanist_load_libraries($working_copy->getProjectConfig('load'), $must_load = true, $lib_source = 'the "load" setting in ".arcconfig"', $working_copy); // Load libraries in ".arcconfig". Libraries here must load. arcanist_load_libraries(idx($runtime_config, 'load', array()), $must_load = true, $lib_source = 'the --config "load=[...]" argument', $working_copy); } $user_config = $configuration_manager->readUserConfigurationFile(); $config_class = $working_copy->getProjectConfig('arcanist_configuration'); if ($config_class) { $config = new $config_class(); } else { $config = new ArcanistConfiguration(); } $command = strtolower($args[0]); $args = array_slice($args, 1); $workflow = $config->selectWorkflow($command, $args, $configuration_manager, $console); $workflow->setConfigurationManager($configuration_manager); $workflow->setArcanistConfiguration($config); $workflow->setCommand($command); $workflow->setWorkingDirectory($working_directory); $workflow->parseArguments($args); // Write the command into the environment so that scripts (for example, local // Git commit hooks) can detect that they're being run via `arc` and change // their behaviors. putenv('ARCANIST=' . $command); if ($force_conduit_version) { $workflow->forceConduitVersion($force_conduit_version);
public static function resolveAliases($command, ArcanistConfiguration $config, array $argv, ArcanistWorkingCopyIdentity $working_copy) { $aliases = ArcanistAliasWorkflow::getAliases($working_copy); if (!isset($aliases[$command])) { return array(null, $argv); } $new_command = head($aliases[$command]); $workflow = $config->buildWorkflow($new_command); if (!$workflow) { return array(null, $argv); } $alias_argv = array_slice($aliases[$command], 1); foreach ($alias_argv as $alias_arg) { if (!in_array($alias_arg, $argv)) { array_unshift($argv, $alias_arg); } } return array($new_command, $argv); }
// fail hard here because this file is edited manually, so if 'arc' breaks // that doesn't make it any more difficult to correct. arcanist_load_libraries(idx($system_config, 'load', array()), $must_load = true, $lib_source = 'the "load" setting in system config', $working_copy, $config_trace_mode); // Load libraries in global 'load' config, as per "arc set-config load". We // need to fail softly if these break because errors would prevent the user // from running "arc set-config" to correct them. arcanist_load_libraries(idx($global_config, 'load', array()), $must_load = false, $lib_source = 'the "load" setting in global config', $working_copy, $config_trace_mode); // Load libraries in ".arcconfig". Libraries here must load. arcanist_load_libraries($working_copy->getConfig('phutil_libraries'), $must_load = true, $lib_source = 'the "phutil_libraries" setting in ".arcconfig"', $working_copy, $config_trace_mode); } $user_config = ArcanistBaseWorkflow::readUserConfigurationFile(); $config = $working_copy->getConfig('arcanist_configuration'); if ($config) { $config = new $config(); } else { $config = new ArcanistConfiguration(); } $command = strtolower($args[0]); $args = array_slice($args, 1); $workflow = $config->buildWorkflow($command); if (!$workflow) { // If the user has an alias, like 'arc alias dhelp diff help', look it up // and substitute it. We do this only after trying to resolve the workflow // normally to prevent you from doing silly things like aliasing 'alias' // to something else. $aliases = ArcanistAliasWorkflow::getAliases($working_copy); list($new_command, $args) = ArcanistAliasWorkflow::resolveAliases($command, $config, $args, $working_copy); $full_alias = idx($aliases, $command, array()); $full_alias = implode(' ', $full_alias); // Run shell command aliases. if (ArcanistAliasWorkflow::isShellCommandAlias($new_command)) {
// fail hard here because this file is edited manually, so if 'arc' breaks // that doesn't make it any more difficult to correct. arcanist_load_libraries(idx($system_config, 'load', array()), $must_load = true, $lib_source = 'the "load" setting in system config', $working_copy); // Load libraries in global 'load' config, as per "arc set-config load". We // need to fail softly if these break because errors would prevent the user // from running "arc set-config" to correct them. arcanist_load_libraries(idx($global_config, 'load', array()), $must_load = false, $lib_source = 'the "load" setting in global config', $working_copy); // Load libraries in ".arcconfig". Libraries here must load. arcanist_load_libraries($working_copy->getConfig('load'), $must_load = true, $lib_source = 'the "load" setting in ".arcconfig"', $working_copy); } $user_config = ArcanistBaseWorkflow::readUserConfigurationFile(); $config_class = $working_copy->getConfig('arcanist_configuration'); if ($config_class) { $config = new $config_class(); } else { $config = new ArcanistConfiguration(); } $command = strtolower($args[0]); $args = array_slice($args, 1); $workflow = $config->selectWorkflow($command, $args, $working_copy, $console); $workflow->setArcanistConfiguration($config); $workflow->setCommand($command); $workflow->setWorkingDirectory($working_directory); $workflow->parseArguments($args); if ($force_conduit_version) { $workflow->forceConduitVersion($force_conduit_version); } if ($conduit_timeout) { $workflow->setConduitTimeout($conduit_timeout); } $need_working_copy = $workflow->requiresWorkingCopy();