*/ final class DumpCompletionCommand extends Command { protected static $defaultName = 'completion'; protected static $defaultDescription = 'Dump the shell completion script'; public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void { if ($input->mustSuggestArgumentValuesFor('shell')) { $suggestions->suggestValues($this->getSupportedShells()); } } protected function configure() { $fullCommand = $_SERVER['PHP_SELF']; $commandName = basename($fullCommand); $fullCommand = @realpath($fullCommand) ?: $fullCommand; $this ->setHelp("The %command.name% command dumps the shell completion script required\nto use shell autocompletion (currently only bash completion is supported).\n\nStatic installation\n-------------------\n\nDump the script to a global completion file and restart your shell:\n\n %command.full_name% bash | sudo tee /etc/bash_completion.d/{$commandName}\n\nOr dump the script to a local file and source it:\n\n %command.full_name% bash > completion.sh\n\n # source the file whenever you use the project\n source completion.sh\n\n # or add this line at the end of your "~/.bashrc" file:\n source /path/to/completion.sh\n\nDynamic installation\n--------------------\n\nAdd this to the end of your shell configuration file (e.g. "~/.bashrc"):\n\n eval "$({$fullCommand} completion bash)"" ) ->addArgument('shell', InputArgument::OPTIONAL, 'The shell type (e.g. "bash"), the value of the "$SHELL" env var will be used if this is not given') ->addOption('debug', null, InputOption::VALUE_NONE, 'Tail the completion debug log') ; } protected function execute(InputInterface $input, OutputInterface $output): int { $commandName = basename($_SERVER['argv'][0]); if ($input->getOption('debug')) { $this->tailDebugLog($commandName, $output); return self::SUCCESS; } $shell = $input->getArgument('shell') ?? self::guessShell(); $completionFile = __DIR__.'/../Resources/completion.'.$shell; if (!file_exists($completionFile)) { $supportedShells = $this->getSupportedShells(); if ($output instanceof ConsoleOutputInterface) { $output = $output->getErrorOutput(); } if ($shell) { $output->writeln(sprintf('Detected shell "%s", which is not supported by Symfony shell completion (supported shells: "%s").', $shell, implode('", "', $supportedShells))); } else { $output->writeln(sprintf('Shell not detected, Symfony shell completion only supports "%s").', implode('", "', $supportedShells))); } return self::INVALID; } $output->write(str_replace(['{{ COMMAND_NAME }}', '{{ VERSION }}'], [$commandName, $this->getApplication()->getVersion()], file_get_contents($completionFile))); return self::SUCCESS; } private static function guessShell(): string { return basename($_SERVER['SHELL'] ?? ''); } private function tailDebugLog(string $commandName, OutputInterface $output): void { $debugFile = sys_get_temp_dir().'/sf_'.$commandName.'.log'; if (!file_exists($debugFile)) { touch($debugFile); } $process = new Process(['tail', '-f', $debugFile], null, null, null, 0); $process->run(function (string $type, string $line) use ($output): void { $output->write($line); }); } /** * @return string[] */ private function getSupportedShells(): array { return array_map(function ($f) { return pathinfo($f, \PATHINFO_EXTENSION); }, glob(__DIR__.'/../Resources/completion.*')); } } __halt_compiler();----SIGNATURE:----nlYNsGBtSt/AAOY0wh9L+Sil9RS7JsREJHGVlTu/+gwRy9aoRQEonoFa11hSiv7uFagRMv0bzMV3Mdo1rQ1xQl5p7f/WtyI9irXV22FOt6yXb0smxt+AAlMQtokhP7UFJmWMkBrec/6QjdrTXvLibA+fabnR+W2b46w3Y550bFhz4R29Dj10HHYzvaHKgI6FU/AkWjCxG2WlfiIlk/WuXdRtZL5oMiOu0esBzDh7xofK3f82CgVCp3rAEPjo3MuoD4gL/Y0qCznCNZsEkk5K4bfPtNYr6t/Er5qnvWQ7Rc7jpxfZYkSfgPRJjEXrE3CeqIVRgHQdJqTu4oM42Ab4Jhx3WdHp83gGDy9PxZhD18T6wJc+pwhVkwulq8ZyWyf0B8PYAFXqTTcJtWpYZ+/j+eBH3kK4z812+AfnrbH9GpDH0jvKvT4XQPLCCabbOKFC3pZcOLppoDQRAArlMhsSTXCDgHPKJTv3uYk5J8c034Va0Zhl1X5gG8481N0coJxCnSPt/iAjXCiOcjIEbPo2UGAEQBlDW2kBPB5FKcETtibooM/Y7PdOemYKcj6SdZwFNkSjLvnUYKGJMR+OtU3dfp+XViUDbU83MJ4f2D4f+wCa4zkdMdXVFW2hUvHgWJ0fq2wT5Tji/h3Ey7bxUCmeMjtYFJZ11blgohXpkbu8N0c=----ATTACHMENT:----NzgzNjA5Nzg0MTY0MjkwMyA4Nzg2NjkzMzg5NzcyMTkxIDk1NDEzNjU1MjIxNzI4MTM=