Skip to content

Commit 1a9fc7a

Browse files
committed
Merge pull request #39 from aik099/38-support-for-shortened-commands
Support command argument/option completion, when command short form is used
2 parents da52d9a + a447d12 commit 1a9fc7a

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/CompletionHandler.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ public function runCompletion()
8282
}
8383

8484
$cmdName = $this->getInput()->getFirstArgument();
85-
if ($this->application->has($cmdName)) {
86-
$this->command = $this->application->get($cmdName);
85+
86+
try {
87+
$this->command = $this->application->find($cmdName);
88+
} catch (\InvalidArgumentException $e) {
89+
// Exception thrown, when multiple or none commands are found.
8790
}
8891

8992
$process = array(

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,16 @@ public function completionAwareCommandDataProvider()
131131
),
132132
);
133133
}
134+
135+
public function testShortCommandMatched()
136+
{
137+
$handler = $this->createHandler('app w:n --deploy');
138+
$this->assertEquals(array('--deploy:jazz-hands'), $this->getTerms($handler->runCompletion()));
139+
}
140+
141+
public function testShortCommandNotMatched()
142+
{
143+
$handler = $this->createHandler('app w --deploy');
144+
$this->assertEquals(array(), $this->getTerms($handler->runCompletion()));
145+
}
134146
}

0 commit comments

Comments
 (0)