File tree Expand file tree Collapse file tree 3 files changed +49
-8
lines changed
src/Symfony/Component/Console/Completion Expand file tree Collapse file tree 3 files changed +49
-8
lines changed Original file line number Diff line number Diff line change @@ -26,25 +26,29 @@ class CompletionSuggestions
26
26
/**
27
27
* Add a suggested value for an input option or argument.
28
28
*
29
+ * @param string|Suggestion $value
30
+ *
29
31
* @return $this
30
32
*/
31
- public function suggestValue (string $ value ): self
33
+ public function suggestValue ($ value ): self
32
34
{
33
- $ this ->valueSuggestions [] = $ value ;
35
+ $ this ->valueSuggestions [] = ! $ value instanceof Suggestion ? new Suggestion ( $ value ) : false ;
34
36
35
37
return $ this ;
36
38
}
37
39
38
40
/**
39
41
* Add multiple suggested values at once for an input option or argument.
40
42
*
41
- * @param string[] $values
43
+ * @param list< string|Suggestion> $values
42
44
*
43
45
* @return $this
44
46
*/
45
47
public function suggestValues (array $ values ): self
46
48
{
47
- $ this ->valueSuggestions = array_merge ($ this ->valueSuggestions , $ values );
49
+ foreach ($ values as $ value ) {
50
+ $ this ->suggestValue ($ value );
51
+ }
48
52
49
53
return $ this ;
50
54
}
@@ -86,7 +90,7 @@ public function getOptionSuggestions(): array
86
90
}
87
91
88
92
/**
89
- * @return string []
93
+ * @return Suggestion []
90
94
*/
91
95
public function getValueSuggestions (): array
92
96
{
Original file line number Diff line number Diff line change @@ -21,10 +21,10 @@ class BashCompletionOutput implements CompletionOutputInterface
21
21
{
22
22
public function write (CompletionSuggestions $ suggestions , OutputInterface $ output ): void
23
23
{
24
- $ options = $ suggestions ->getValueSuggestions ();
24
+ $ suggestions = $ suggestions ->getValueSuggestions ();
25
25
foreach ($ suggestions ->getOptionSuggestions () as $ option ) {
26
- $ options [] = '-- ' .$ option ->getName ();
26
+ $ suggestions [] = '-- ' .$ option ->getName ();
27
27
}
28
- $ output ->writeln (implode ("\n" , $ options ));
28
+ $ output ->writeln (implode ("\n" , $ suggestions ));
29
29
}
30
30
}
Original file line number Diff line number Diff line change
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
+ namespace Symfony \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
+ private string $ value ;
22
+
23
+ public function __construct (string $ value )
24
+ {
25
+ $ this ->value = $ value ;
26
+ }
27
+
28
+ public function getValue (): string
29
+ {
30
+ return $ this ->value ;
31
+ }
32
+
33
+ public function __toString (): string
34
+ {
35
+ return $ this ->getValue ();
36
+ }
37
+ }
You can’t perform that action at this time.
0 commit comments