stecman / symfony-console-completion

Automatic tab-key completion for Symfony console application options, arguments and parameters
MIT License
420 stars 26 forks source link

Support for shortened commands #38

Closed aik099 closed 9 years ago

aik099 commented 9 years ago

Symfony Console allow to type d:r when command name is deploy:run. In such case would program d:r TAB produce any auto-complete for deploy:run command?

pjcdawkins commented 9 years ago

No, not at the moment (so this is a feature request).

But: program d TAB : r TAB TAB would be the same as program deploy:run TAB

aik099 commented 9 years ago

Are you sure? Because code, used to get command from application by name (see https://github.com/stecman/symfony-console-completion/blob/master/src/CompletionHandler.php#L84-L87) theoretically should also account for shortened command versions.

pjcdawkins commented 9 years ago

Yes - well, at least, it doesn't work for me!

pjcdawkins commented 9 years ago

Maybe something changed, I'm still using v0.4.4 - I'll test with the latest dev-master

aik099 commented 9 years ago

Ah, I've found it. There 2 methods on console application:

So instead of doing has + get we should be doing find + catch exception on no match or multiple match and consider command as not found.

pjcdawkins commented 9 years ago

Sounds good! It's presumably going to be slow(er), particularly for the commands that are not found (you can't stop it doing the levenshtein-based findAlternatives()), but I imagine it's negligible

aik099 commented 9 years ago

you can't stop it doing the levenshtein-based findAlternatives()

What is this?

stecman commented 9 years ago

Hmm ok, good to know that it's possible at least. Personally I don't see a huge benefit in adding support for this since, as @pjcdawkins hinted at, having auto-completion kind of makes shortcuts like these redundant.

My other concern is that having single character values in completion results ends up being a bit clunky; you'd normally type one letter and press tab, but if the shell gets d and deploy back, it'll complete to 'd' and require another character of input to finish the completion. This would need to be implemented to magically work, but not clutter the regular results.

aik099 commented 9 years ago

having auto-completion kind of makes shortcuts like these redundant.

Not really. Instead pressing d TAB : TAB r TAB to get deploy:run you can press d : r and that's all.

My other concern is that having single character values in completion results ends up being a bit clunky;

You misunderstood. I'm not changing what command names are auto-completed - still full command names with namespace there. I'm only changing fact, that when command-related stuff is auto-completed it will know the command from it's short name.

aik099 commented 9 years ago

Here is PR to better illustrate this. Tests speak for themselves.

stecman commented 9 years ago

@aik099 - thanks, merged and released as 0.5.1.

aik099 commented 9 years ago

I'm not using this right now, but I think it works as expected since tests pass for me.

aik099 commented 9 years ago

@stecman , it's 00:58 where you living if I'm not mistaken? You should be sleeping right now ;)