Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Console] Add completion values to input definition#44948

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
GromNaN merged 1 commit intosymfony:6.1fromGromNaN:console-completion-definition
Mar 17, 2022

Conversation

@GromNaN
Copy link
Member

@GromNaNGromNaN commentedJan 7, 2022
edited
Loading

QA
Branch?6.1
Bug fix?no
New feature?yes
Deprecations?no
Ticketsn/a
LicenseMIT
Doc PRsymfony/symfony-docs#...

During implementation of bash completion to core commands, I found the code quite verbose. The completion for all options and arguments are mixed into the same method.

Example of current code

publicfunctioncomplete(CompletionInput$input,CompletionSuggestions$suggestions):void
{
if ($input->mustSuggestArgumentValuesFor('command_name')) {
$descriptor =newApplicationDescription($this->getApplication());
$suggestions->suggestValues(array_keys($descriptor->getCommands()));
return;
}
if ($input->mustSuggestOptionValuesFor('format')) {
$helper =newDescriptorHelper();
$suggestions->suggestValues($helper->getFormats());
}
}

This PR adds the possibility to attach values to each option and argument in their definition. It provides a default implementation ofCommand::complete that uses this values.

In the constructor of theInputOption andInputArgument classes:

newInputArgument('command_name', InputArgument::OPTIONAL,'The command name','help',function () {
returnarray_keys((newApplicationDescription($this->getApplication()))->getCommands());
}),
newInputOption('format',null, InputOption::VALUE_REQUIRED,'The output format (txt, xml, json, or md)','txt',function () {
return (newDescriptorHelper())->getFormats();
}),

Or usingCommand::addOption andCommand::addArgument:

->addArgument('shell', InputArgument::OPTIONAL,'The shell type (e.g. "bash"), the value of the "$SHELL" env var will be used if this is not given',null,fn () =>$this->getSupportedShells())

Additional benefits:

Todo:

  • Add tests
  • Add info to descriptor

wouterj reacted with heart emoji
@GromNaNGromNaNforce-pushed theconsole-completion-definition branch 2 times, most recently from8650876 todfb4cc6CompareJanuary 7, 2022 22:29
@wouterj
Copy link
Member

wouterj commentedJan 7, 2022
edited
Loading

I haven't looked at the code yet, but I really like the idea. See also these 2 comments on the original PR:#42251 Being able to predict whether an option has a value or not and maybe even dumping the static values to the completion file (e.g. for apps like Composer) are 2 other very interesting advantages of this approach.

Fromhttps://github.com/posener/complete , mentioned in the comments I referenced above, I especially like the Predict enum:

 "name":      predict.Set{"foo", "bar", "foo bar"}, "something": predict.Something, "nothing":   predict.Nothing,

Set: values are static, can be dumped (or described)
Something: We'll have to invoke the_complete command for this
Nothing: Skip completion, this option has no value (or value is not autocompletable).

We can even extend this with e.g. Files, to enable the great file completion system of shell completion.

@GromNaNGromNaNforce-pushed theconsole-completion-definition branch 2 times, most recently from0f93398 tof8e03dbCompareJanuary 8, 2022 12:15
@GromNaN
Copy link
MemberAuthor

GromNaN commentedJan 10, 2022
edited
Loading

After you comment@wouterj, I think we can use a union type that covers each cases.

  • true: callingcomplete.
  • false: disable completion
  • \Closure: call it
  • iterable: get fixed values from the iterable
  • null: not defined, will callcomplete by default. Settingnull should be deprecated and becomefalse by default in7.0.

We must stay open to file completion once we'd have managed to get it work#43607.

@GromNaNGromNaNforce-pushed theconsole-completion-definition branch fromf8e03db toc4d65b3CompareFebruary 13, 2022 22:07
@GromNaNGromNaNforce-pushed theconsole-completion-definition branch fromc4d65b3 toab40533CompareFebruary 14, 2022 08:58
@GromNaNGromNaNforce-pushed theconsole-completion-definition branch 2 times, most recently frome668ed4 to0e31423CompareFebruary 14, 2022 14:20
@GromNaNGromNaNforce-pushed theconsole-completion-definition branch 4 times, most recently fromd1a2af5 to80654e5CompareFebruary 15, 2022 14:58
Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

Much better :)

@GromNaNGromNaNforce-pushed theconsole-completion-definition branch from80654e5 to5d70c9bCompareFebruary 15, 2022 18:30
@GromNaN
Copy link
MemberAuthor

Thank you for all your time for this review. We have something very clear now.

@GromNaNGromNaNforce-pushed theconsole-completion-definition branch 3 times, most recently from091027a to4f9c779CompareMarch 16, 2022 18:43
@GromNaN
Copy link
MemberAuthor

@chalasr@wouterj ready for a new review. Description updated.

Copy link
Member

@chalasrchalasr left a comment

Choose a reason for hiding this comment

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

Great. Just one minor question

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

Some last minute nitpicking;

@GromNaNGromNaNforce-pushed theconsole-completion-definition branch 3 times, most recently fromae8e882 toa2a2e67CompareMarch 17, 2022 15:56
@GromNaNGromNaNforce-pushed theconsole-completion-definition branch froma2a2e67 to95ad05fCompareMarch 17, 2022 16:09
@nicolas-grekas
Copy link
Member

What about this todo?

Add info to descriptor

@GromNaN
Copy link
MemberAuthor

What about this todo?

Add info to descriptor

Could be part of an other PR.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@chalasrchalasrchalasr approved these changes

@wouterjwouterjAwaiting requested review from wouterj

+1 more reviewer

@dkarlovidkarlovidkarlovi left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

6.1

Development

Successfully merging this pull request may close these issues.

6 participants

@GromNaN@wouterj@nicolas-grekas@dkarlovi@chalasr@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp