Skip to content

Commit dd6d37d

Browse files
committed
Add command name completion for composer help
Resolves #3
1 parent bb5e1da commit dd6d37d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/ComposerCompletionCommand.php

+20
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Stecman\Component\Symfony\Console\BashCompletion;
44

55
use Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand;
6+
use Stecman\Component\Symfony\Console\BashCompletion\Completion;
67

78
class ComposerCompletionCommand extends CompletionCommand
89
{
@@ -25,6 +26,25 @@ protected function runCompletion()
2526
);
2627
}
2728

29+
// Complete for `help` command's `command` argument
30+
$application = $this->getApplication();
31+
$this->handler->addHandler(
32+
new Completion(
33+
'help',
34+
'command_name',
35+
Completion::TYPE_ARGUMENT,
36+
function() use ($application) {
37+
$names = array_keys($application->all());
38+
39+
if ($key = array_search('_completion', $names)) {
40+
unset($names[$key]);
41+
}
42+
43+
return $names;
44+
}
45+
)
46+
);
47+
2848
return $this->handler->runCompletion();
2949
}
3050
}

0 commit comments

Comments
 (0)