/src/Codeception/Command/GenerateHelper.php
PHP | 52 lines | 38 code | 8 blank | 6 comment | 2 complexity | fd8d35f8e08e07397d698e8fa3c54db9 MD5 | raw file
- <?php
- namespace Codeception\Command;
- use Codeception\Lib\Generator\Helper;
- use Symfony\Component\Console\Input\InputArgument;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Input\InputOption;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Console\Command\Command;
- /**
- * Creates empty Helper class.
- *
- * * `codecept g:helper MyHelper`
- *
- */
- class GenerateHelper extends Command
- {
- use Shared\FileSystem;
- use Shared\Config;
- protected function configure()
- {
- $this->setDefinition(
- array(
- new InputArgument('name', InputArgument::REQUIRED, 'suite to be generated'),
- new InputOption('config', 'c', InputOption::VALUE_OPTIONAL, 'Use custom path for config'),
- )
- );
- }
- public function getDescription()
- {
- return 'Generates new helper';
- }
- public function execute(InputInterface $input, OutputInterface $output)
- {
- $name = ucfirst($input->getArgument('name'));
- $config = \Codeception\Configuration::config($input->getOption('config'));
- $file = \Codeception\Configuration::helpersDir() . "{$name}Helper.php";
- $res = $this->save($file, (new Helper($name, $config['namespace']))->produce());
- if ($res) {
- $output->writeln("<info>Helper $file created</info>");
- } else {
- $output->writeln("<error>Error creating helper $file</error>");
- }
- }
- }