1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-09 16:32:39 +01:00

Tailor CLI feedback about "arc alias" to describe shell command aliases

Summary:
Fixes T9873. Instead of printing something like this:

> Aliased "arc ls" to "arc !ls".

...print this:

> Aliased "arc ls" to shell command "ls".

Test Plan:
  - Added shell commands and internal aliases.
  - Removed aliases.
  - Listed aliases.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9873

Differential Revision: https://secure.phabricator.com/D14651
This commit is contained in:
epriestley 2015-12-03 06:02:05 -08:00
parent cdaad096fa
commit 4a680c762b

View file

@ -83,54 +83,42 @@ EOTEXT
$argv = $this->getArgument('argv');
if (count($argv) == 0) {
if ($aliases) {
foreach ($aliases as $alias => $binding) {
echo phutil_console_format(
"**%s** %s\n",
$alias,
implode(' ' , $binding));
}
} else {
echo pht("You haven't defined any aliases yet.")."\n";
}
$this->printAliases($aliases);
} else if (count($argv) == 1) {
if (empty($aliases[$argv[0]])) {
echo pht("No alias '%s' to remove.", $argv[0])."\n";
} else {
echo pht(
"'%s' is currently aliased to '%s'.",
phutil_console_format('**arc %s**', $argv[0]),
phutil_console_format(
'**arc %s**',
implode(' ', $aliases[$argv[0]])));
$ok = phutil_console_confirm(pht('Delete this alias?'));
if ($ok) {
$was = implode(' ', $aliases[$argv[0]]);
unset($aliases[$argv[0]]);
$this->writeAliases($aliases);
echo pht("Unaliased '%s' (was '%s').", $argv[0], $was)."\n";
} else {
throw new ArcanistUserAbortException();
}
}
$this->removeAlias($aliases, $argv[0]);
} else {
$arc_config = $this->getArcanistConfiguration();
$alias = $argv[0];
if ($arc_config->buildWorkflow($argv[0])) {
if ($arc_config->buildWorkflow($alias)) {
throw new ArcanistUsageException(
pht(
"You can not create an alias for '%s' because it is a ".
"builtin command. '%s' can only create new commands.",
$argv[0],
'You can not create an alias for "%s" because it is a '.
'builtin command. "%s" can only create new commands.',
"arc {$alias}",
'arc alias'));
}
$aliases[$argv[0]] = array_slice($argv, 1);
echo pht(
"Aliased '%s' to '%s'.\n",
phutil_console_format('**arc %s**', $argv[0]),
phutil_console_format('**arc %s**', implode(' ', $aliases[$argv[0]])));
$new_alias = array_slice($argv, 1);
$command = implode(' ', $new_alias);
if (self::isShellCommandAlias($command)) {
echo tsprintf(
"%s\n",
pht(
'Aliased "%s" to shell command "%s".',
"arc {$alias}",
substr($command, 1)));
} else {
echo tsprintf(
"%s\n",
pht(
'Aliased "%s" to "%s".',
"arc {$alias}",
"arc {$command}"));
}
$aliases[$alias] = $new_alias;
$this->writeAliases($aliases);
}
@ -173,4 +161,83 @@ EOTEXT
return array($new_command, $argv);
}
private function printAliases(array $aliases) {
if (!$aliases) {
echo tsprintf(
"%s\n",
pht('You have not defined any aliases yet.'));
return;
}
$table = id(new PhutilConsoleTable())
->addColumn('input', array('title' => pht('Alias')))
->addColumn('command', array('title' => pht('Command')))
->addColumn('type', array('title' => pht('Type')));
ksort($aliases);
foreach ($aliases as $alias => $binding) {
$command = implode(' ', $binding);
if (self::isShellCommandAlias($command)) {
$command = substr($command, 1);
$type = pht('Shell Command');
} else {
$command = "arc {$command}";
$type = pht('Arcanist Command');
}
$row = array(
'input' => "arc {$alias}",
'type' => $type,
'command' => $command,
);
$table->addRow($row);
}
$table->draw();
}
private function removeAlias(array $aliases, $alias) {
if (empty($aliases[$alias])) {
echo tsprintf(
"%s\n",
pht('No alias "%s" to remove.', $alias));
return;
}
$command = implode(' ', $aliases[$alias]);
if (self::isShellCommandAlias($command)) {
echo tsprintf(
"%s\n",
pht(
'"%s" is currently aliased to shell command "%s".',
"arc {$alias}",
substr($command, 1)));
} else {
echo tsprintf(
"%s\n",
pht(
'"%s" is currently aliased to "%s".',
"arc {$alias}",
"arc {$command}"));
}
$ok = phutil_console_confirm(pht('Delete this alias?'));
if (!$ok) {
throw new ArcanistUserAbortException();
}
unset($aliases[$alias]);
$this->writeAliases($aliases);
echo tsprintf(
"%s\n",
pht(
'Removed alias "%s".',
"arc {$alias}"));
}
}