Skip to content

[Console] Add completion to help & list commands #43596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2021

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Oct 19, 2021

Q A
Branch? 5.4
Bug fix? no
New feature? yes
Deprecations? no
Tickets #43594
License MIT
Doc PR no
  • Add completion for commands help and list
  • Create a tester class to wrap completion code in tests
  • To autocomplete option --format, supported formats are exposed by DescriptorHelper

throw new \LogicException(sprintf('Command "%s" must implement "%s" to support completion.', \get_class($this->command), CompletionInput::class));
}

$currentIndex = \count($input);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we make this a parameter (e.g. for cases where the suggestions for argument 1 is different based on argument 2?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please open a PR. The index thing is tricky and I don't know to deal with it.

@wouterj
Copy link
Member

wouterj commented Oct 20, 2021

Thank you for starting this initiative @GromNaN !

@fabpot
Copy link
Member

fabpot commented Oct 20, 2021

Thank you @GromNaN.


public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
{
if ($input->mustSuggestArgumentValuesFor('namespace')) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be an improvement to create a "Helper", in order to have common functions for complete and calling it like this:

public function shouldSuggestValues(string $type): void {
    if ($input->mustSuggestArgumentValuesFor($type)) {
        $descriptor = new ApplicationDescription($this->getApplication());
        $suggestions->suggestValues(array_keys($descriptor->getNamespaces()));

        return;
    }

    if ($input->mustSuggestOptionValuesFor('format')) {
        $helper = new DescriptorHelper();
        $suggestions->suggestValues($helper->getFormats());
    }
}

And calling it in the complete function for ListCommand.php and HelpCommand.php?

// ListCommand.php
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
{
    $this->commandHelper->shouldSuggestValues('namespace');
}
// HelpCommand.php
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
{
    $this->commandHelper->shouldSuggestValues('command_name');
}

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a helper knowing about argument names of all Symfony commands does not make sense (and would require to make argument names unique across all commands)

@BenjaminRbt
Copy link

Oups, didn't see it was already merged @GromNaN

I guess no need to take my comment into account.

*
* @author Jérôme Tamarelle <jerome@tamarelle.net>
*/
class CommandCompletionTester
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this one final

@GromNaN GromNaN deleted the complete/list-help branch October 22, 2021 08:51
fabpot added a commit that referenced this pull request Oct 30, 2021
…, form, messenger, router (IonBazan)

This PR was merged into the 5.4 branch.

Discussion
----------

[Console] add suggestions for debug commands: firewall, form, messenger, router

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | #43594
| License       | MIT
| Doc PR        | -

Adding Bash completion for following commands:

- `debug:firewall`
- `debug:form`
- `debug:messenger`
- `debug:router`

~Waiting for #43596 to be merged first as it adds testing utilities and `DescriptorHelper::getFormats()`.~

Commits
-------

eaf9461 add suggestions for debug:firewall, debug:form, debug:messenger, debug:router
This was referenced Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants