Ensure that the directory doesn't already exist
This commit is contained in:
parent
d17c1defcf
commit
0ece90c6cf
7 changed files with 217 additions and 4 deletions
src
51
src/Command/GenerateDrupal7Command.php
Normal file
51
src/Command/GenerateDrupal7Command.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Opdavies\DrupalModuleGenerator\Command;
|
||||
|
||||
use Opdavies\DrupalModuleGenerator\Exception\CannotCreateModuleException;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class GenerateDrupal7Command extends Command
|
||||
{
|
||||
private $moduleName;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $defaultName = 'generate-drupal-7-module';
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setDescription('Generate a new Drupal 7 module.')
|
||||
->addArgument('module-name', InputArgument::REQUIRED, 'The name of the module to create');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->moduleName = $input->getArgument('module-name');
|
||||
|
||||
$this->ensureDirectoryDoesNotExist();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the directory name for the module doesn't already exist.
|
||||
*/
|
||||
private function ensureDirectoryDoesNotExist()
|
||||
{
|
||||
if (is_dir($this->moduleName)) {
|
||||
throw CannotCreateModuleException::directoryAlreadyExists();
|
||||
}
|
||||
}
|
||||
}
|
11
src/Exception/CannotCreateModuleException.php
Normal file
11
src/Exception/CannotCreateModuleException.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Opdavies\DrupalModuleGenerator\Exception;
|
||||
|
||||
class CannotCreateModuleException extends \RuntimeException
|
||||
{
|
||||
public static function directoryAlreadyExists()
|
||||
{
|
||||
return new static('The given directory name for the module already exists.');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue