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

Commitf5667b0

Browse files
committed
Add Suggestion class for more advanced completion suggestion
1 parentc94aa6f commitf5667b0

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

‎src/Symfony/Component/Console/Completion/CompletionSuggestions.php‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,29 @@ class CompletionSuggestions
2626
/**
2727
* Add a suggested value for an input option or argument.
2828
*
29+
* @param string|Suggestion $value
30+
*
2931
* @return $this
3032
*/
31-
publicfunctionsuggestValue(string$value):self
33+
publicfunctionsuggestValue($value):self
3234
{
33-
$this->valueSuggestions[] =$value;
35+
$this->valueSuggestions[] =!$valueinstanceof Suggestion ?newSuggestion($value) :false;
3436

3537
return$this;
3638
}
3739

3840
/**
3941
* Add multiple suggested values at once for an input option or argument.
4042
*
41-
* @param string[] $values
43+
* @paramlist<string|Suggestion> $values
4244
*
4345
* @return $this
4446
*/
4547
publicfunctionsuggestValues(array$values):self
4648
{
47-
$this->valueSuggestions =array_merge($this->valueSuggestions,$values);
49+
foreach ($valuesas$value) {
50+
$this->suggestValue($value);
51+
}
4852

4953
return$this;
5054
}
@@ -86,7 +90,7 @@ public function getOptionSuggestions(): array
8690
}
8791

8892
/**
89-
* @returnstring[]
93+
* @returnSuggestion[]
9094
*/
9195
publicfunctiongetValueSuggestions():array
9296
{

‎src/Symfony/Component/Console/Completion/Output/BashCompletionOutput.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class BashCompletionOutput implements CompletionOutputInterface
2121
{
2222
publicfunctionwrite(CompletionSuggestions$suggestions,OutputInterface$output):void
2323
{
24-
$options =$suggestions->getValueSuggestions();
24+
$suggestions =$suggestions->getValueSuggestions();
2525
foreach ($suggestions->getOptionSuggestions()as$option) {
26-
$options[] ='--'.$option->getName();
26+
$suggestions[] ='--'.$option->getName();
2727
}
28-
$output->writeln(implode("\n",$options));
28+
$output->writeln(implode("\n",$suggestions));
2929
}
3030
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Console\Completion;
13+
14+
/**
15+
* Represents a single suggested value.
16+
*
17+
* @author Wouter de Jong <wouter@wouterj.nl>
18+
*/
19+
class Suggestion
20+
{
21+
privatestring$value;
22+
23+
publicfunction__construct(string$value)
24+
{
25+
$this->value =$value;
26+
}
27+
28+
publicfunctiongetValue():string
29+
{
30+
return$this->value;
31+
}
32+
33+
publicfunction__toString():string
34+
{
35+
return$this->getValue();
36+
}
37+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp