1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-22 14:52:40 +01:00

Allow defining aliases in .arcconfig.

Summary:
For Objective-C repositories, we want to provide aliases to
arc diff --amend-autofixes by default.

This adds the ability to define aliases in .arcconfig (overridden
by any specified in the user config, of course).

Test Plan:
Tested defining alias with nothing in .arcconfig, with
an alias in .arcconfig.  Tested arc alias outside of working
repository.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran

Differential Revision: https://secure.phabricator.com/D2191
This commit is contained in:
Ben Gertzfield 2012-04-10 11:29:25 -07:00
parent 14d49d2565
commit 2c02e79df4
4 changed files with 24 additions and 12 deletions

View file

@ -168,7 +168,8 @@ try {
list($new_command, $args) = ArcanistAliasWorkflow::resolveAliases( list($new_command, $args) = ArcanistAliasWorkflow::resolveAliases(
$command, $command,
$config, $config,
$args); $args,
$working_copy);
if ($new_command) { if ($new_command) {
$workflow = $config->buildWorkflow($new_command); $workflow = $config->buildWorkflow($new_command);
@ -179,7 +180,7 @@ try {
"Unknown command '{$command}'. Try 'arc help'."); "Unknown command '{$command}'. Try 'arc help'.");
} else { } else {
if ($config_trace_mode) { if ($config_trace_mode) {
$aliases = ArcanistAliasWorkflow::getAliases(); $aliases = ArcanistAliasWorkflow::getAliases($working_copy);
$target = implode(' ', idx($aliases, $command, array())); $target = implode(' ', idx($aliases, $command, array()));
echo "[alias: 'arc {$command}' -> 'arc {$target}']\n"; echo "[alias: 'arc {$command}' -> 'arc {$target}']\n";
} }

View file

@ -17,7 +17,7 @@
*/ */
/** /**
* Show which revision or revisions are in the working copy. * Manages aliases for commands with options.
* *
* @group workflow * @group workflow
*/ */
@ -62,9 +62,14 @@ EOTEXT
); );
} }
public static function getAliases() { public static function getAliases($working_copy) {
$config = self::readUserConfigurationFile(); $working_copy_config_aliases = $working_copy->getConfig('aliases');
return idx($config, 'aliases', array()); if (!$working_copy_config_aliases) {
$working_copy_config_aliases = array();
}
$user_config_aliases =
idx(self::readUserConfigurationFile(), 'aliases', array());
return $user_config_aliases + $working_copy_config_aliases;
} }
private function writeAliases(array $aliases) { private function writeAliases(array $aliases) {
@ -74,8 +79,10 @@ EOTEXT
} }
public function run() { public function run() {
// We might not be in a working directory, so we don't want to require a
$aliases = self::getAliases(); // working copy identity here.
$working_copy = ArcanistWorkingCopyIdentity::newFromPath(getcwd());
$aliases = self::getAliases($working_copy);
$argv = $this->getArgument('argv'); $argv = $this->getArgument('argv');
if (count($argv) == 0) { if (count($argv) == 0) {
@ -132,9 +139,10 @@ EOTEXT
public static function resolveAliases( public static function resolveAliases(
$command, $command,
ArcanistConfiguration $config, ArcanistConfiguration $config,
array $argv) { array $argv,
ArcanistWorkingCopyIdentity $working_copy) {
$aliases = ArcanistAliasWorkflow::getAliases(); $aliases = ArcanistAliasWorkflow::getAliases($working_copy);
if (!isset($aliases[$command])) { if (!isset($aliases[$command])) {
return array(null, $argv); return array(null, $argv);
} }

View file

@ -9,6 +9,7 @@
phutil_require_module('arcanist', 'exception/usage'); phutil_require_module('arcanist', 'exception/usage');
phutil_require_module('arcanist', 'exception/usage/userabort'); phutil_require_module('arcanist', 'exception/usage/userabort');
phutil_require_module('arcanist', 'workflow/base'); phutil_require_module('arcanist', 'workflow/base');
phutil_require_module('arcanist', 'workingcopyidentity');
phutil_require_module('phutil', 'console'); phutil_require_module('phutil', 'console');
phutil_require_module('phutil', 'utils'); phutil_require_module('phutil', 'utils');

View file

@ -100,7 +100,8 @@ EOTEXT
} }
// Also permit autocompletion of "arc alias" commands. // Also permit autocompletion of "arc alias" commands.
foreach (ArcanistAliasWorkflow::getAliases() as $key => $value) { foreach (
ArcanistAliasWorkflow::getAliases($working_copy) as $key => $value) {
$complete[] = $key; $complete[] = $key;
} }
@ -112,7 +113,8 @@ EOTEXT
list($new_command, $new_args) = ArcanistAliasWorkflow::resolveAliases( list($new_command, $new_args) = ArcanistAliasWorkflow::resolveAliases(
$argv[1], $argv[1],
$arc_config, $arc_config,
array_slice($argv, 2)); array_slice($argv, 2),
$working_copy);
if ($new_command) { if ($new_command) {
$workflow = $arc_config->buildWorkflow($new_command); $workflow = $arc_config->buildWorkflow($new_command);
} }