mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 06:42:41 +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:
parent
14d49d2565
commit
2c02e79df4
4 changed files with 24 additions and 12 deletions
|
@ -168,7 +168,8 @@ try {
|
|||
list($new_command, $args) = ArcanistAliasWorkflow::resolveAliases(
|
||||
$command,
|
||||
$config,
|
||||
$args);
|
||||
$args,
|
||||
$working_copy);
|
||||
|
||||
if ($new_command) {
|
||||
$workflow = $config->buildWorkflow($new_command);
|
||||
|
@ -179,7 +180,7 @@ try {
|
|||
"Unknown command '{$command}'. Try 'arc help'.");
|
||||
} else {
|
||||
if ($config_trace_mode) {
|
||||
$aliases = ArcanistAliasWorkflow::getAliases();
|
||||
$aliases = ArcanistAliasWorkflow::getAliases($working_copy);
|
||||
$target = implode(' ', idx($aliases, $command, array()));
|
||||
echo "[alias: 'arc {$command}' -> 'arc {$target}']\n";
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* Show which revision or revisions are in the working copy.
|
||||
* Manages aliases for commands with options.
|
||||
*
|
||||
* @group workflow
|
||||
*/
|
||||
|
@ -62,9 +62,14 @@ EOTEXT
|
|||
);
|
||||
}
|
||||
|
||||
public static function getAliases() {
|
||||
$config = self::readUserConfigurationFile();
|
||||
return idx($config, 'aliases', array());
|
||||
public static function getAliases($working_copy) {
|
||||
$working_copy_config_aliases = $working_copy->getConfig('aliases');
|
||||
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) {
|
||||
|
@ -74,8 +79,10 @@ EOTEXT
|
|||
}
|
||||
|
||||
public function run() {
|
||||
|
||||
$aliases = self::getAliases();
|
||||
// We might not be in a working directory, so we don't want to require a
|
||||
// working copy identity here.
|
||||
$working_copy = ArcanistWorkingCopyIdentity::newFromPath(getcwd());
|
||||
$aliases = self::getAliases($working_copy);
|
||||
|
||||
$argv = $this->getArgument('argv');
|
||||
if (count($argv) == 0) {
|
||||
|
@ -132,9 +139,10 @@ EOTEXT
|
|||
public static function resolveAliases(
|
||||
$command,
|
||||
ArcanistConfiguration $config,
|
||||
array $argv) {
|
||||
array $argv,
|
||||
ArcanistWorkingCopyIdentity $working_copy) {
|
||||
|
||||
$aliases = ArcanistAliasWorkflow::getAliases();
|
||||
$aliases = ArcanistAliasWorkflow::getAliases($working_copy);
|
||||
if (!isset($aliases[$command])) {
|
||||
return array(null, $argv);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
phutil_require_module('arcanist', 'exception/usage');
|
||||
phutil_require_module('arcanist', 'exception/usage/userabort');
|
||||
phutil_require_module('arcanist', 'workflow/base');
|
||||
phutil_require_module('arcanist', 'workingcopyidentity');
|
||||
|
||||
phutil_require_module('phutil', 'console');
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
|
|
@ -100,7 +100,8 @@ EOTEXT
|
|||
}
|
||||
|
||||
// Also permit autocompletion of "arc alias" commands.
|
||||
foreach (ArcanistAliasWorkflow::getAliases() as $key => $value) {
|
||||
foreach (
|
||||
ArcanistAliasWorkflow::getAliases($working_copy) as $key => $value) {
|
||||
$complete[] = $key;
|
||||
}
|
||||
|
||||
|
@ -112,7 +113,8 @@ EOTEXT
|
|||
list($new_command, $new_args) = ArcanistAliasWorkflow::resolveAliases(
|
||||
$argv[1],
|
||||
$arc_config,
|
||||
array_slice($argv, 2));
|
||||
array_slice($argv, 2),
|
||||
$working_copy);
|
||||
if ($new_command) {
|
||||
$workflow = $arc_config->buildWorkflow($new_command);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue