Skip to content

Commit

Permalink
Merge pull request #37 from bluzphp/develop
Browse files Browse the repository at this point in the history
Added `--force` option to file generators
  • Loading branch information
Anton authored Nov 28, 2017
2 parents 6e16590 + fad4f3a commit b446619
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 15 deletions.
33 changes: 20 additions & 13 deletions bin/bluzman
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,23 @@ ini_set('display_errors', 1);
ini_set('log_errors', 0);
ini_set('html_errors', 0);

// Get project info from composer.json
$composerConfig = json_decode(
file_get_contents(PATH_VENDOR .DS. 'bluzphp' .DS. 'bluzman' .DS. 'composer.json'),
true
);
require_once PATH_VENDOR . '/autoload.php';

$application = new Bluzman\Application\Application(
$composerConfig['description'],
$composerConfig['version'] ?? 'dev'
);
$application->init();
$application->run();
try {
// Get project info from composer.json
$composerConfig = json_decode(
file_get_contents(PATH_VENDOR . DS . 'bluzphp' . DS . 'bluzman' . DS . 'composer.json'),
true
);
require_once PATH_VENDOR . '/autoload.php';

$application = new Bluzman\Application\Application(
$composerConfig['description'],
$composerConfig['version'] ?? 'dev'
);
$application->init();
$application->run();
} catch (\Throwable $e) {
echo "Error #{$e->getCode()}:\n\n";
echo "\t{$e->getFile()}:{$e->getLine()}\n";
echo "\t{$e->getMessage()}\n";
echo "\n";
}
15 changes: 14 additions & 1 deletion src/Command/Generate/AbstractGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Bluzman\Generator\GeneratorException;
use Bluzman\Input\InputArgument;
use Bluzman\Input\InputException;
use Bluzman\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -31,6 +32,17 @@ abstract class AbstractGenerateCommand extends AbstractCommand
*/
abstract public function verify(InputInterface $input, OutputInterface $output) : void;

/**
* Add Force Option
*
* @return void
*/
protected function addForceOption() : void
{
$force = new InputOption('--force', '-f', InputOption::VALUE_NONE, 'Rewrite previously generated files');
$this->getDefinition()->addOption($force);
}

/**
* Add Model Argument
*
Expand Down Expand Up @@ -142,8 +154,9 @@ protected function getTemplate($class)
*/
protected function generateFile($class, $file, array $data = []) : void
{
if (file_exists($file)) {
if (file_exists($file) && !$this->getInput()->getOption('force')) {
$this->comment(" |> File <info>$file</info> already exists");
return;
}

$template = $this->getTemplate($class);
Expand Down
1 change: 1 addition & 0 deletions src/Command/Generate/ControllerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ protected function configure()

$this->addModuleArgument();
$this->addControllerArgument();
$this->addForceOption();
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Command/Generate/CrudCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ protected function configure()
->setDescription('Generate a CRUD for model')
// the full command description shown when running the command with
// the "--help" option
->setHelp('This command allows you to generate CRUD files');
->setHelp('This command allows you to generate CRUD files')
;

$this->addModelArgument();
$this->addModuleArgument(InputArgument::OPTIONAL);
$this->addForceOption();
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Command/Generate/GridCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected function configure()

$this->addModelArgument();
$this->addModuleArgument(InputArgument::OPTIONAL);
$this->addForceOption();
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Command/Generate/ModelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ protected function configure()

$this->addModelArgument();
$this->addTableArgument();
$this->addForceOption();
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Command/Generate/ModuleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected function configure()
;

$this->addModuleArgument();
$this->addForceOption();
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Command/Generate/RestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ protected function configure()

$this->addModelArgument();
$this->addModuleArgument();
$this->addForceOption();
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Command/Generate/ScaffoldCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected function configure()
$this->addModelArgument();
$this->addTableArgument();
$this->addModuleArgument();
$this->addForceOption();
}

/**
Expand Down

0 comments on commit b446619

Please sign in to comment.