Changeset View
Changeset View
Standalone View
Standalone View
src/toolset/ArcanistAliasWorkflow.php
- This file was moved from src/workflow/ArcanistAliasWorkflow.php.
| <?php | <?php | ||||
| /** | /** | ||||
| * Manages aliases for commands with options. | * Manages aliases for commands with options. | ||||
| */ | */ | ||||
| final class ArcanistAliasWorkflow extends ArcanistWorkflow { | final class ArcanistAliasWorkflow extends ArcanistWorkflow { | ||||
| public function getWorkflowName() { | public function getWorkflowName() { | ||||
| return 'alias'; | return 'alias'; | ||||
| } | } | ||||
| public function getCommandSynopses() { | public function supportsToolset(ArcanistToolset $toolset) { | ||||
| return phutil_console_format(<<<EOTEXT | return true; | ||||
| **alias** | } | ||||
| **alias** __command__ | |||||
| **alias** __command__ __target__ -- [__options__] | public function getWorkflowSynopses() { | ||||
| EOTEXT | return array( | ||||
| pht('**alias**'), | |||||
| pht('**alias** __command__'), | |||||
| pht('**alias** __command__ __target__ -- [__options__]'), | |||||
| ); | ); | ||||
| } | } | ||||
| public function getCommandHelp() { | public function getWorkflowHelp() { | ||||
| return phutil_console_format(<<<EOTEXT | return pht(<<<EOTEXT | ||||
| Supports: cli | Supports: cli | ||||
| Create an alias from __command__ to __target__ (optionally, with | Create an alias from __command__ to __target__ (optionally, with __options__). | ||||
| __options__). For example: | For example: | ||||
| arc alias fpatch patch -- --force | %s alias fpatch patch -- --force | ||||
| ...will create a new 'arc' command, 'arc fpatch', which invokes | ...will create a new 'arc' command, 'arc fpatch', which invokes | ||||
| 'arc patch --force ...' when run. NOTE: use "--" before specifying | 'arc patch --force ...' when run. NOTE: use "--" before specifying | ||||
| options! | options! | ||||
| If you start an alias with "!", the remainder of the alias will be | If you start an alias with "!", the remainder of the alias will be | ||||
| invoked as a shell command. For example, if you want to implement | invoked as a shell command. For example, if you want to implement | ||||
| 'arc ls', you can do so like this: | 'arc ls', you can do so like this: | ||||
| arc alias ls '!ls' | %s alias ls '!ls' | ||||
| You can now run "arc ls" and it will behave like "ls". Of course, this | You can now run "arc ls" and it will behave like "ls". Of course, this | ||||
| example is silly and would make your life worse. | example is silly and would make your life worse. | ||||
| You can not overwrite builtins, including 'alias' itself. The builtin | You can not overwrite builtins, including 'alias' itself. The builtin | ||||
| will always execute, even if it was added after your alias. | will always execute, even if it was added after your alias. | ||||
| To remove an alias, run: | To remove an alias, run: | ||||
| arc alias fpatch | arc alias fpatch | ||||
| Without any arguments, 'arc alias' will list aliases. | Without any arguments, 'arc alias' will list aliases. | ||||
| EOTEXT | EOTEXT | ||||
| ); | , | ||||
| $this->getToolsetName()); | |||||
| } | } | ||||
| public function getArguments() { | public function getArguments() { | ||||
| return array( | return array( | ||||
| '*' => 'argv', | '*' => 'argv', | ||||
| ); | ); | ||||
| } | } | ||||
| Show All 10 Lines | EOTEXT | ||||
| } | } | ||||
| private function writeAliases(array $aliases) { | private function writeAliases(array $aliases) { | ||||
| $config = $this->getConfigurationManager()->readUserConfigurationFile(); | $config = $this->getConfigurationManager()->readUserConfigurationFile(); | ||||
| $config['aliases'] = $aliases; | $config['aliases'] = $aliases; | ||||
| $this->getConfigurationManager()->writeUserConfigurationFile($config); | $this->getConfigurationManager()->writeUserConfigurationFile($config); | ||||
| } | } | ||||
| public function run() { | public function runWorkflow() { | ||||
| $aliases = self::getAliases($this->getConfigurationManager()); | $aliases = self::getAliases($this->getConfigurationManager()); | ||||
| $argv = $this->getArgument('argv'); | $argv = $this->getArgument('argv'); | ||||
| if (count($argv) == 0) { | if (count($argv) == 0) { | ||||
| $this->printAliases($aliases); | $this->printAliases($aliases); | ||||
| } else if (count($argv) == 1) { | } else if (count($argv) == 1) { | ||||
| $this->removeAlias($aliases, $argv[0]); | $this->removeAlias($aliases, $argv[0]); | ||||
| } else { | } else { | ||||
| ▲ Show 20 Lines • Show All 154 Lines • Show Last 20 Lines | |||||