setName('generate:doc:cheatsheet') ->setDescription($this->trans('commands.generate.doc.cheatsheet.description')) ->addOption( 'path', null, InputOption::VALUE_OPTIONAL, $this->trans('commands.generate.doc.cheatsheet.options.path') ) ->addOption( 'wkhtmltopdf', null, InputOption::VALUE_OPTIONAL, $this->trans('commands.generate.doc.cheatsheet.options.wkhtmltopdf') ); ; } /** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $path = null; if ($input->hasOption('path')) { $path = $input->getOption('path'); } if (!$path) { $io->error( $this->trans('commands.generate.doc.gitbook.messages.missing_path') ); return 1; } // $wkhtmltopdfPath is overwritable by command option if ($input->getOption('wkhtmltopdf')) { $this->wkhtmltopdfPath = $input->getOption('wkhtmltopdf'); } $application = $this->getApplication(); $command_list = []; foreach ($this->singleCommands as $single_command) { $command = $application->find($single_command); $command_list['none'][] = [ 'name' => $command->getName(), 'description' => $command->getDescription(), ]; } $namespaces = $application->getNamespaces(); sort($namespaces); $namespaces = array_filter( $namespaces, function ($item) { return (strpos($item, ':')<=0); } ); foreach ($namespaces as $namespace) { $commands = $application->all($namespace); usort( $commands, function ($cmd1, $cmd2) { return strcmp($cmd1->getName(), $cmd2->getName()); } ); foreach ($commands as $command) { if ($command->getModule()=='Console') { $command_list[$namespace][] = [ 'name' => $command->getName(), 'description' => $command->getDescription(), ]; } } } if (!empty($command_list)) { $this->prepareHtml($command_list, $path, $io); } } /** * Generates (programatically, not with twig) the HTML to convert to PDF * * @param array $array_content * @param string $path */ protected function prepareHtml($array_content, $path, $io) { $str = ''; $str .= "
DrupalConsole Cheatsheet |