stecman / symfony-console-completion

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

Auto-complete for built-in help and list commands #40

Closed aik099 closed 9 years ago

aik099 commented 9 years ago

There is a built-in help command, that accepts other command name (to show help for) as 1st optional argument. No possible argument values are defined in command itself because it's instance is created before all commands were added to application.

By adding following to _completetion command it will be possible to auto-complete command names for help command:

/**
 * Configure the CompletionHandler instance before it is run
 *
 * @param CompletionHandler $handler Completion handler.
 *
 * @return void
 */
protected function configureCompletion(CompletionHandler $handler)
{
    $handler->addHandler(
        new Completion(
            'help',
            'command_name',
            Completion::TYPE_ARGUMENT,
            array_keys($this->getApplication()->all())
        )
    );
}

This method is currently empty for Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand command.

If agreed I can add it to base command or we can just keep it as snippet somewhere in documentation.

stecman commented 9 years ago

This would be good to have. Happy to accept a PR.

The other default command, list, has an optional namespace argument if you wanted to add a built-in completion for that at the same time.

aik099 commented 9 years ago

White trying to test this I've stumbled upon a problem. In tests the CompletionHandler::runCompletion method is used, however, when doing auto-complete from CLI the CompletionCommand::runCompletion method is used, which also calls the CompletionCommand::configureCompletion method I've changed.

Because of this I have no way to test that code I've added works.

stecman commented 9 years ago

A few thoughts:

aik099 commented 9 years ago

Should these default completions live in CompletionHandler instead of CompletionCommand? I can't decide at the moment.

Ha, you're right. When I added them I was looking as end user, which can only add them to CompletionCommand::configureCompletion method. But since they are default completion handlers then they should be added in there.

In any case if developer wants to override them he/she can do this by adding completion helper with same arguments.

aik099 commented 9 years ago

PR created. No need to immediately create new minor release this time, because I might come up with something else because I'm using this library on one of active projects now.

You can do a release once a month if that's no serious bug of course.

stecman commented 9 years ago

Great, thanks. I'll hold off on doing a release for a while :+1: