8000 feat: add completion for DebugConfig name and path arguments · symfony/symfony@6403892 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6403892

Browse files
committed
feat: add completion for DebugConfig name and path arguments
1 parent bd08495 commit 6403892

File tree

2 files changed

+94
-5
lines changed

2 files changed

+94
-5
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use Symfony\Component\Config\Definition\ConfigurationInterface;
1515
use Symfony\Component\Config\Definition\Processor;
16+
use Symfony\Component\Console\Completion\CompletionInput;
17+
use Symfony\Component\Console\Completion\CompletionSuggestions;
1618
use Symfony\Component\Console\Exception\LogicException;
1719
use Symfony\Component\Console\Input\InputArgument;
1820
use Symfony\Component\Console\Input\InputInterface;
@@ -94,11 +96,7 @@ protected function 8000 execute(InputInterface $input, OutputInterface $output): int
9496
$extensionAlias = $extension->getAlias();
9597
$container = $this->compileContainer();
9698

97-
$config = $container->resolveEnvPlaceholders(
98-
$container->getParameterBag()->resolveValue(
99-
$this->getConfigForExtension($extension, $container)
100-
)
101-
);
99+
$config = $this->getConfig($extension, $container);
102100

103101
if (null === $path = $input->getArgument('path')) {
104102
$io->title(
@@ -188,4 +186,53 @@ private function getConfigForExtension(ExtensionInterface $extension, ContainerB
188186

189187
return (new Processor())->processConfiguration($configuration, $configs);
190188
}
189+
190+
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
191+
{
192+
$name = strtolower($input->getArgument('name'));
193+
194+
if ($input->mustSuggestArgumentValuesFor('name')) {
195+
$suggestions->suggestValues($this->getBundlesCompletion($name));
196+
}
197+
198+
if ($input->mustSuggestArgumentValuesFor('path') && null !== $name) {
199+
$path = $input->getArgument('path');
200+
$extension = $this->findExtension($name);
201+
$extensionAlias = $extension->getAlias();
202+
$container = $this->compileContainer();
203+
204+
try {
205+
$config = $this->getConfigForPath($this->getConfig($extension, $container), $path, $extensionAlias);
206+
} catch (LogicException $e) {
207+
$config = [];
208+
}
209+
210+
$suggestions->suggestValues(array_keys($config));
211+
}
212+
}
213+
214+
private function getBundlesCompletion(string $name): array
215+
{
216+
$bundles = [];
217+
foreach ($this->getApplication()->getKernel()->getBundles() as $bundle) {
218+
$bundleName = $bundle->getName();
219+
$bundleAlias = $bundle->getContainerExtension()->getAlias();
220+
221+
if (str_starts_with(strtolower($bundleName), $name)) {
222+
$bundles[] = $bundleName;
223+
$bundles[] = $bundleAlias;
224+
}
225+
}
226+
227+
return $bundles;
228+
}
229+
230+
private function getConfig(ExtensionInterface $extension, ContainerBuilder $container)
231+
{
232+
return $container->resolveEnvPlaceholders(
233+
$container->getParameterBag()->resolveValue(
234+
$this->getConfigForExtension($extension, $container)
235+
)
236+
);
237+
}
191238
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
1313

14+
use Symfony\Bundle\FrameworkBundle\Command\ConfigDebugCommand;
1415
use Symfony\Bundle\FrameworkBundle\Console\Application;
1516
use Symfony\Component\Console\Input\ArrayInput;
1617
use Symfony\Component\Console\Output\NullOutput;
18+
use Symfony\Component\Console\Tester\CommandCompletionTester;
1719
use Symfony\Component\Console\Tester\CommandTester;
1820

1921
/**
@@ -111,6 +113,46 @@ public function testDumpThrowsExceptionWhenDefaultConfigFallbackIsImpossible()
111113
$tester->execute(['name' => 'ExtensionWithoutConfigTestBundle']);
112114
}
113115

116+
/**
117+
* @dataProvider provideCompletionSuggestions
118+
*/
119+
public function testComplete(array $input, array $expectedSuggestions)
120+
{
121+
$this->application->add(new ConfigDebugCommand());
122+
123+
$tester = new CommandCompletionTester($this->application->get('debug:config'));
124+
125+
$suggestions = $tester->complete($input, 2);
126+
127+
$this->assertSame($expectedSuggestions, $suggestions);
128+
}
129+
130+
public function provideCompletionSuggestions(): \Generator
131+
{
132+
yield 'name' => [
133+
['default'],
134+
[
135+
'DefaultConfigTestBundle',
136+
'default_config_test',
137+
],
138+
];
139+
140+
yield 'name with existing path' => [
141+
['framework', 'uid'],
142+
[
143+
'enabled',
144+
'default_uuid_version',
145+
'name_based_uuid_version',
146+
'time_based_uuid_version',
147+
],
148+
];
149+
150+
yield 'name with unknown path' => [
151+
['default_config_test', 'uid'],
152+
[],
153+
];
154+
}
155+
114156
private function createCommandTester(): CommandTester
115157
{
116158
$command = $this->application->find('debug:config');

0 commit comments

Comments
 (0)
0