-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
c26a37f
to
145c0f7
Compare
throw new \LogicException(sprintf('Command "%s" must implement "%s" to support completion.', \get_class($this->command), CompletionInput::class)); | ||
} | ||
|
||
$currentIndex = \count($input); |
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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.
Thank you for starting this initiative @GromNaN ! |
Thank you @GromNaN. |
a6e5f8f
to
dc94c72
Compare
|
||
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void | ||
{ | ||
if ($input->mustSuggestArgumentValuesFor('namespace')) { |
There was a problem hiding this comment.
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');
}
?
There was a problem hiding this comment.
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)
* | ||
* @author Jérôme Tamarelle <jerome@tamarelle.net> | ||
*/ | ||
class CommandCompletionTester |
There was a problem hiding this comment.
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
…, 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
help
andlist
--format
, supported formats are exposed byDescriptorHelper