Similar to the "svn checkout" vs "svn co".. this was requested in #528016: Create ishacked drush command.

CommentFileSizeAuthor
#4 drush.aliases.patch1.78 KBIncrediblyKenzi

Comments

moshe weitzman’s picture

i think git allows for personal aliases in a config file. is that whats requested here? why not use bashrc for that?

sethcohn’s picture

This is more along the lines of 'svn co' being equiv to 'svn checkout'.

With the current drush command options, there is no way to do aliases cleanly.
The iscorehacked patch used a method that 'works': define a new command, then just call the truly desired command, but the side effect is that both show up as unique commands in the show commands list. This was considered undesirable, and so it was removed.

Adding true alias support would allow 'drush en' to be equiv to 'drush enable', for example.

moshe weitzman’s picture

OK - command defined aliases then. Anyone up for a patch?

IncrediblyKenzi’s picture

Status: Active » Needs review
StatusFileSize
new1.78 KB

Yup.. here ya go.

Hides aliases from the command output. Not sure if we want a help option for showing aliases.

But basically in hook_drush_command you can define:

$items['mycommand'] = array(
  'description' => dt('my description here'),
  'aliases' => array('mycommandalias'),
);
jonhattan’s picture

I've applied the patch and defined a 'aliases' => array('a', 'b') in a command. It worked nice.

sethcohn’s picture

Looks good. +1.

Potential and very optional suggestions:

1) Add an alias argument to help, to also show aliases for all commands.

2) alias existing commonly used core commands:

watchdog = wd
enable = en
disable = dis
status = stat
statusmodules = sm
update = up
updatecode = upc
updatedb = updb

dl = download (hmm, interestingly, this is a shortcut name, but does not have a long form 'english' name unlike every other drush command,
if nothing else, this one is worth doing just to fix that)

rsvelko’s picture

The most important part of this thing is that we will collaboratively agree on a certain map of aliases. Standartization will do great in this area - else everybody will try to invent his own aliases in bashrc...

jonhattan’s picture

`dl` could be changed to `download` and `dl` be an alias for `download`.

moshe weitzman’s picture

Status: Needs review » Needs work

Is anyone else concerned that we will see lots of collisions in alias names? How can we handle that gracefully? Could we drop into interactive mode and ask the user what he means?

We need to tell the user about aliases. The most logical place IMO is in the main help table. We should append the alias list to the command name. So, something like: watchdog show (ws).

Makes sense to add the list that set proposes in #6 along with jonhattan suggestion in #8 (dl as an alias for download).

anarcat’s picture

I agree we should watch out for collisions. In case of ambiguity, just exit with an error.

I would rather have 'dl' be an alias and 'download' the real command if we go that way.

Ideally, drush could guess which command you want if you type just enough characters too, so we wouldn't have to define explicit aliases all the time. I think this is how svn works.

But I don't oppose the patch per se. I think it would need documentation however.

moshe weitzman’s picture

Lets deal with collisions in another issue. They are not handled well today, so we need not introduce handling here.

I looked at this again and am now happy to have it. Could someone extend the patch do that we display aliases on the main help output and on the commmand detail help? Also, lets add aliases per $6 and #8. #8 can be a followup patch.

moshe weitzman’s picture

Status: Needs work » Fixed

I went ahead and implemented all that we discussed here and then committed. This is pretty nice.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

dman’s picture

Small issue arising from the alias code - with E_ALL, I get a huge list of
Undefined index: is_alias
from drush itself.
eg when just running drush -v help.

A tidy fix is

diff -u -p -r1.50 core.drush.inc
--- commands/core/core.drush.inc        30 Oct 2009 21:55:13 -0000      1.50
+++ commands/core/core.drush.inc        3 Nov 2009 04:36:59 -0000
@@ -222,7 +222,7 @@ function drush_core_help() {
         
         $rows = array();
         foreach($commands as $key => $command) {
-          if (!$command['is_alias']) {
+          if (empty($command['is_alias'])) {
             if (!array_key_exists($key, $printed_rows)) {
               $name = $command['aliases'] ? $key . ' (' . implode(', ', $command['aliases']) . ')': $key;
               $rows[$key] = array($name, $command['description']);

Placed against this issue, not a new one, because it's pretty small - a post-commit review :-)
(Looking at it, I realize it's highly unlikely a sane person would want verbose help ... but hey, I hit it :-)

brad.bulger’s picture

i hit that too, debugging my own command files. i take the 5th on the issue of sanity, though.