Skip to content

Commit 91b3e1a

Browse files
committed
Require specification of program name for --genhook
1 parent 95baef9 commit 91b3e1a

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/Stecman/Component/Symfony/Console/BashCompletion/CompletionCommand.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ protected function configure()
2121
->setName('_completion')
2222
->setDescription('BASH completion hook.')
2323
->setHelp(<<<END
24-
To enable BASH completion, run: <comment>eval `beam completion --genhook`</comment>
24+
To enable BASH completion, run: <comment>eval `beam completion --genhook="app-name"`</comment>
2525
END
2626
)
2727
->addOption(
2828
'genhook',
29-
null,
30-
InputOption::VALUE_NONE,
31-
'Generate BASH script to enable completion using this command'
29+
'g',
30+
InputOption::VALUE_REQUIRED,
31+
'Generate BASH script to use completion with this application. <comment>Requires program name as value.</comment>'
3232
);
3333
}
3434

@@ -37,9 +37,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
3737
$this->handler = new CompletionHandler( $this->getApplication() );
3838
$handler = $this->handler;
3939

40-
if ($input->getOption('genhook')) {
41-
$bash = $handler->generateBashCompletionHook();
42-
$output->write($bash, true);
40+
if ($programName = $input->getOption('genhook')) {
41+
$output->write( $handler->generateBashCompletionHook($programName), true );
4342
} else {
4443
$handler->configureFromEnvironment();
4544
$output->write($this->runCompletion(), true);

src/Stecman/Component/Symfony/Console/BashCompletion/CompletionHandler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Symfony\Component\Console\Command\Command as BaseCommand;
77
use Symfony\Component\Console\Input\ArrayInput;
88
use Symfony\Component\Console\Input\InputArgument;
9-
use Symfony\Component\Console\Input\InputDefinition;
109
use Symfony\Component\Console\Input\InputOption;
1110

1211
class CompletionHandler {
@@ -344,10 +343,11 @@ protected function filterResults($array)
344343
}
345344

346345
/**
347-
* Return the BASH script necessary to use bash completion with this handler
346+
* Return the BASH script necessary to use bash completion with this addHandler
347+
* @param string $programName
348348
* @return string
349349
*/
350-
public function generateBashCompletionHook()
350+
public function generateBashCompletionHook($programName)
351351
{
352352
global $argv;
353353
$command = $argv[0];
@@ -357,7 +357,7 @@ function _beamcomplete {
357357
export COMP_CWORD COMP_KEY COMP_LINE COMP_POINT COMP_WORDBREAKS;
358358
COMPREPLY=(`compgen -W "$($command _completion)"`);
359359
};
360-
complete -F _beamcomplete beam;
360+
complete -F _beamcomplete $programName;
361361
END;
362362
}
363363

0 commit comments

Comments
 (0)