Skip to content

Commit 47bf604

Browse files
committed
Merge pull request #43 from aik099/40-auto-complete-for-build-in-commands
Auto-complete arguments of built-in "help" and "list" commands
2 parents 1a9fc7a + 1ee7b9c commit 47bf604

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/CompletionCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected function runCompletion()
9494
*/
9595
protected function configureCompletion(CompletionHandler $handler)
9696
{
97-
// Override this method to configure custom value completions
97+
// Override this method to configure custom value completions
9898
}
9999

100100
/**

src/CompletionHandler.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ public function __construct(Application $application, CompletionContext $context
3838
{
3939
$this->application = $application;
4040
$this->context = $context;
41+
42+
$this->addHandler(
43+
new Completion(
44+
'help',
45+
'command_name',
46+
Completion::TYPE_ARGUMENT,
47+
array_keys($application->all())
48+
)
49+
);
50+
51+
$this->addHandler(
52+
new Completion(
53+
'list',
54+
'namespace',
55+
Completion::TYPE_ARGUMENT,
56+
$application->getNamespaces()
57+
)
58+
);
4159
}
4260

4361
public function setContext(CompletionContext $context)

tests/Stecman/Component/Symfony/Console/BashCompletion/CompletionHandlerTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,22 @@ public function testShortCommandNotMatched()
143143
$handler = $this->createHandler('app w --deploy');
144144
$this->assertEquals(array(), $this->getTerms($handler->runCompletion()));
145145
}
146+
147+
public function testHelpCommandCompletion()
148+
{
149+
$handler = $this->createHandler('app help ');
150+
$this->assertEquals(
151+
array('help', 'list', 'completion-aware', 'wave', 'walk:north'),
152+
$this->getTerms($handler->runCompletion())
153+
);
154+
}
155+
156+
public function testListCommandCompletion()
157+
{
158+
$handler = $this->createHandler('app list ');
159+
$this->assertEquals(
160+
array('walk'),
161+
$this->getTerms($handler->runCompletion())
162+
);
163+
}
146164
}

0 commit comments

Comments
 (0)