[command] Naming + minor fixes on commands

This commit is contained in:
William DURAND 2011-09-05 22:18:18 +02:00
parent cbcc89ea61
commit 4dcdc0f3b9
16 changed files with 55 additions and 57 deletions

View file

@ -18,12 +18,12 @@ use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\HttpKernel\Util\Filesystem; use Symfony\Component\HttpKernel\Util\Filesystem;
/** /**
* Wrapper command for Phing tasks * Wrapper for Propel commands.
* *
* @author Fabien Potencier <fabien.potencier@symfony-project.com> * @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author William DURAND <william.durand1@gmail.com> * @author William DURAND <william.durand1@gmail.com>
*/ */
abstract class PhingCommand extends ContainerAwareCommand abstract class AbstractPropelCommand extends ContainerAwareCommand
{ {
/** /**
* Additional Phing args to add in specialized commands. * Additional Phing args to add in specialized commands.
@ -314,17 +314,13 @@ EOT;
$properties = array(); $properties = array();
if (false === $lines = @file($file)) { if (false === $lines = @file($file)) {
throw new sfCommandException('Unable to parse contents of the "sqldb.map" file.'); throw new \Exception(sprintf('Unable to parse contents of "%s".', $file));
} }
foreach ($lines as $line) { foreach ($lines as $line) {
$line = trim($line); $line = trim($line);
if ('' == $line) { if ('' == $line || in_array($line[0], array('#', ';'))) {
continue;
}
if (in_array($line[0], array('#', ';'))) {
continue; continue;
} }
@ -363,7 +359,7 @@ EOT;
throw new \InvalidArgumentException(sprintf('Connection named %s doesn\'t exist', $name)); throw new \InvalidArgumentException(sprintf('Connection named %s doesn\'t exist', $name));
} }
$output->writeln(sprintf('<info>[Propel] Use connection named <comment>%s</comment></info>', $name)); $output->writeln(sprintf('<info>Use connection named</info> <comment>%s</comment>.', $name));
return array($name, $defaultConfig); return array($name, $defaultConfig);
} }
@ -430,18 +426,6 @@ EOT;
)); ));
} }
/**
* Ask confirmation from the user.
*
* @param OutputInterface $output The output.
* @param string $question A given question.
* @param string $default A default response.
*/
protected function askConfirmation(OutputInterface $output, $question, $default = null)
{
return $this->getHelperSet()->get('dialog')->askConfirmation($output, $question, $default);
}
/** /**
* Renders an error message if a task has failed. * Renders an error message if a task has failed.
* *
@ -468,4 +452,16 @@ EOT;
{ {
return $output->writeln('>> <info>File+</info> ' . $filename); return $output->writeln('>> <info>File+</info> ' . $filename);
} }
/**
* Ask confirmation from the user.
*
* @param OutputInterface $output The output.
* @param string $question A given question.
* @param string $default A default response.
*/
protected function askConfirmation(OutputInterface $output, $question, $default = null)
{
return $this->getHelperSet()->get('dialog')->askConfirmation($output, $question, $default);
}
} }

View file

@ -10,7 +10,7 @@
namespace Propel\PropelBundle\Command; namespace Propel\PropelBundle\Command;
use Propel\PropelBundle\Command\PhingCommand; use Propel\PropelBundle\Command\AbstractPropelCommand;
use Propel\PropelBundle\Command\BuildModelCommand; use Propel\PropelBundle\Command\BuildModelCommand;
use Propel\PropelBundle\Command\BuildSqlCommand; use Propel\PropelBundle\Command\BuildSqlCommand;
@ -26,7 +26,7 @@ use Symfony\Component\Console\Output\Output;
* @author Fabien Potencier <fabien.potencier@symfony-project.com> * @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author William DURAND <william.durand1@gmail.com> * @author William DURAND <william.durand1@gmail.com>
*/ */
class BuildCommand extends PhingCommand class BuildCommand extends AbstractPropelCommand
{ {
/** /**
* @see Command * @see Command

View file

@ -10,7 +10,7 @@
namespace Propel\PropelBundle\Command; namespace Propel\PropelBundle\Command;
use Propel\PropelBundle\Command\PhingCommand; use Propel\PropelBundle\Command\AbstractPropelCommand;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@ -20,7 +20,7 @@ use Symfony\Component\Console\Output\OutputInterface;
* @author Fabien Potencier <fabien.potencier@symfony-project.com> * @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author William DURAND <william.durand1@gmail.com> * @author William DURAND <william.durand1@gmail.com>
*/ */
class BuildModelCommand extends PhingCommand class BuildModelCommand extends AbstractPropelCommand
{ {
/** /**
* @see Command * @see Command

View file

@ -18,7 +18,7 @@ use Symfony\Component\Console\Output\Output;
use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\Util\Filesystem; use Symfony\Component\HttpKernel\Util\Filesystem;
use Propel\PropelBundle\Command\PhingCommand; use Propel\PropelBundle\Command\AbstractPropelCommand;
/** /**
* BuildCommand. * BuildCommand.
@ -26,7 +26,7 @@ use Propel\PropelBundle\Command\PhingCommand;
* @author Fabien Potencier <fabien.potencier@symfony-project.com> * @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author William DURAND <william.durand1@gmail.com> * @author William DURAND <william.durand1@gmail.com>
*/ */
class BuildSqlCommand extends PhingCommand class BuildSqlCommand extends AbstractPropelCommand
{ {
/** /**
* @see Command * @see Command

View file

@ -10,7 +10,7 @@
namespace Propel\PropelBundle\Command; namespace Propel\PropelBundle\Command;
use Propel\PropelBundle\Command\PhingCommand; use Propel\PropelBundle\Command\AbstractPropelCommand;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@ -22,7 +22,7 @@ use Symfony\Component\HttpKernel\Util\Filesystem;
* *
* @author William DURAND <william.durand1@gmail.com> * @author William DURAND <william.durand1@gmail.com>
*/ */
class DataDumpCommand extends PhingCommand class DataDumpCommand extends AbstractPropelCommand
{ {
protected static $destPath = '/propel/dump'; protected static $destPath = '/propel/dump';

View file

@ -10,7 +10,7 @@
namespace Propel\PropelBundle\Command; namespace Propel\PropelBundle\Command;
use Propel\PropelBundle\Command\PhingCommand; use Propel\PropelBundle\Command\AbstractPropelCommand;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@ -22,7 +22,7 @@ use Symfony\Component\HttpKernel\Util\Filesystem;
* *
* @author William DURAND <william.durand1@gmail.com> * @author William DURAND <william.durand1@gmail.com>
*/ */
class DataSqlCommand extends PhingCommand class DataSqlCommand extends AbstractPropelCommand
{ {
/** /**
* @see Command * @see Command

View file

@ -10,7 +10,7 @@
namespace Propel\PropelBundle\Command; namespace Propel\PropelBundle\Command;
use Propel\PropelBundle\Command\PhingCommand; use Propel\PropelBundle\Command\AbstractPropelCommand;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
@ -21,7 +21,7 @@ use Symfony\Component\Console\Input\InputOption;
* *
* @author William DURAND * @author William DURAND
*/ */
class DatabaseCreateCommand extends PhingCommand class DatabaseCreateCommand extends AbstractPropelCommand
{ {
/** /**
* @see Command * @see Command

View file

@ -10,7 +10,7 @@
namespace Propel\PropelBundle\Command; namespace Propel\PropelBundle\Command;
use Propel\PropelBundle\Command\PhingCommand; use Propel\PropelBundle\Command\AbstractPropelCommand;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
@ -21,7 +21,7 @@ use Symfony\Component\Console\Input\InputOption;
* *
* @author William DURAND * @author William DURAND
*/ */
class DatabaseDropCommand extends PhingCommand class DatabaseDropCommand extends AbstractPropelCommand
{ {
/** /**
* @see Command * @see Command

View file

@ -10,7 +10,7 @@
namespace Propel\PropelBundle\Command; namespace Propel\PropelBundle\Command;
use Propel\PropelBundle\Command\PhingCommand; use Propel\PropelBundle\Command\AbstractPropelCommand;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@ -20,7 +20,7 @@ use Symfony\Component\Console\Output\OutputInterface;
* *
* @author William DURAND <william.durand1@gmail.com> * @author William DURAND <william.durand1@gmail.com>
*/ */
class GraphvizCommand extends PhingCommand class GraphvizCommand extends AbstractPropelCommand
{ {
/** /**
* @see Command * @see Command

View file

@ -10,7 +10,7 @@
namespace Propel\PropelBundle\Command; namespace Propel\PropelBundle\Command;
use Propel\PropelBundle\Command\PhingCommand; use Propel\PropelBundle\Command\AbstractPropelCommand;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@ -20,7 +20,7 @@ use Symfony\Component\Console\Output\OutputInterface;
* *
* @author William DURAND <william.durand1@gmail.com> * @author William DURAND <william.durand1@gmail.com>
*/ */
class InsertSqlCommand extends PhingCommand class InsertSqlCommand extends AbstractPropelCommand
{ {
/** /**
* @see Command * @see Command

View file

@ -17,7 +17,7 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\Util\Filesystem; use Symfony\Component\HttpKernel\Util\Filesystem;
use Propel\PropelBundle\Command\PhingCommand; use Propel\PropelBundle\Command\AbstractPropelCommand;
use Propel\PropelBundle\DataFixtures\YamlDataLoader; use Propel\PropelBundle\DataFixtures\YamlDataLoader;
use Propel\PropelBundle\DataFixtures\XmlDataLoader; use Propel\PropelBundle\DataFixtures\XmlDataLoader;
@ -26,7 +26,7 @@ use Propel\PropelBundle\DataFixtures\XmlDataLoader;
* *
* @author William DURAND <william.durand1@gmail.com> * @author William DURAND <william.durand1@gmail.com>
*/ */
class LoadFixturesCommand extends PhingCommand class LoadFixturesCommand extends AbstractPropelCommand
{ {
/** /**
* Default fixtures directory. * Default fixtures directory.
@ -124,26 +124,26 @@ EOT
} }
if (!$this->absoluteFixturesPath && !file_exists($this->absoluteFixturesPath)) { if (!$this->absoluteFixturesPath && !file_exists($this->absoluteFixturesPath)) {
return $output->writeln('<info>[Propel] The fixtures directory does not exist.</info>'); return $output->writeln('<info>The fixtures directory does not exist.</info>');
} }
$noOptions = (!$input->getOption('xml') && !$input->getOption('sql') && !$input->getOption('yml')); $noOptions = (!$input->getOption('xml') && !$input->getOption('sql') && !$input->getOption('yml'));
if ($input->getOption('sql') || $noOptions) { if ($input->getOption('sql') || $noOptions) {
if (-1 === $this->loadSqlFixtures($input, $output)) { if (-1 === $this->loadSqlFixtures($input, $output)) {
$output->writeln('<info>[Propel] No SQL fixtures found.</info>'); $output->writeln('<info>No SQL fixtures found.</info>');
} }
} }
if ($input->getOption('xml') || $noOptions) { if ($input->getOption('xml') || $noOptions) {
if (-1 === $this->loadFixtures($input, $output, 'xml')) { if (-1 === $this->loadFixtures($input, $output, 'xml')) {
$output->writeln('<info>[Propel] No XML fixtures found.</info>'); $output->writeln('<info>No XML fixtures found.</info>');
} }
} }
if ($input->getOption('yml') || $noOptions) { if ($input->getOption('yml') || $noOptions) {
if (-1 === $this->loadFixtures($input, $output, 'yml')) { if (-1 === $this->loadFixtures($input, $output, 'yml')) {
$output->writeln('<info>[Propel] No YAML fixtures found.</info>'); $output->writeln('<info>No YAML fixtures found.</info>');
} }
} }
} }
@ -218,7 +218,7 @@ EOT
// Create a "sqldb.map" file // Create a "sqldb.map" file
$sqldbContent = ''; $sqldbContent = '';
foreach($datas as $data) { foreach($datas as $data) {
$output->writeln(sprintf('<info>[Propel] Loading SQL fixtures from</info> <comment>%s</comment>', $data)); $output->writeln(sprintf('<info>Loading SQL fixtures from</info> <comment>%s</comment>.', $data));
$sqldbContent .= $data->getFilename() . '=' . $name . PHP_EOL; $sqldbContent .= $data->getFilename() . '=' . $name . PHP_EOL;
$this->filesystem->copy($data, $tmpdir . '/fixtures/' . $data->getFilename(), true); $this->filesystem->copy($data, $tmpdir . '/fixtures/' . $data->getFilename(), true);
@ -272,7 +272,9 @@ EOT
)); ));
if (true === $ret) { if (true === $ret) {
$output->writeln('<info>[Propel] All SQL statements have been executed.</info>'); $this->writeSection($output, array(
'', 'All SQL statements have been executed.'
), 'fg=green;bg=black');
} else { } else {
$this->writeTaskError($output, 'insert-sql', false); $this->writeTaskError($output, 'insert-sql', false);
return false; return false;

View file

@ -10,7 +10,7 @@
namespace Propel\PropelBundle\Command; namespace Propel\PropelBundle\Command;
use Propel\PropelBundle\Command\PhingCommand; use Propel\PropelBundle\Command\AbstractPropelCommand;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@ -19,7 +19,7 @@ use Symfony\Component\Console\Output\OutputInterface;
* *
* @author William DURAND <william.durand1@gmail.com> * @author William DURAND <william.durand1@gmail.com>
*/ */
class MigrationGenerateDiffCommand extends PhingCommand class MigrationGenerateDiffCommand extends AbstractPropelCommand
{ {
/** /**
* @see Command * @see Command

View file

@ -10,7 +10,7 @@
namespace Propel\PropelBundle\Command; namespace Propel\PropelBundle\Command;
use Propel\PropelBundle\Command\PhingCommand; use Propel\PropelBundle\Command\AbstractPropelCommand;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@ -21,7 +21,7 @@ use Symfony\Component\Console\Output\Output;
* *
* @author William DURAND <william.durand1@gmail.com> * @author William DURAND <william.durand1@gmail.com>
*/ */
class MigrationMigrateCommand extends PhingCommand class MigrationMigrateCommand extends AbstractPropelCommand
{ {
/** /**
* @see Command * @see Command

View file

@ -10,7 +10,7 @@
namespace Propel\PropelBundle\Command; namespace Propel\PropelBundle\Command;
use Propel\PropelBundle\Command\PhingCommand; use Propel\PropelBundle\Command\AbstractPropelCommand;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@ -19,7 +19,7 @@ use Symfony\Component\Console\Output\OutputInterface;
* *
* @author William DURAND <william.durand1@gmail.com> * @author William DURAND <william.durand1@gmail.com>
*/ */
class MigrationStatusCommand extends PhingCommand class MigrationStatusCommand extends AbstractPropelCommand
{ {
/** /**
* @see Command * @see Command

View file

@ -10,7 +10,7 @@
namespace Propel\PropelBundle\Command; namespace Propel\PropelBundle\Command;
use Propel\PropelBundle\Command\PhingCommand; use Propel\PropelBundle\Command\AbstractPropelCommand;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@ -22,7 +22,7 @@ use Symfony\Component\HttpKernel\Util\Filesystem;
* *
* @author William DURAND <william.durand1@gmail.com> * @author William DURAND <william.durand1@gmail.com>
*/ */
class ReverseCommand extends PhingCommand class ReverseCommand extends AbstractPropelCommand
{ {
/** /**
* @see Command * @see Command

View file

@ -10,7 +10,7 @@
namespace Propel\PropelBundle\Command; namespace Propel\PropelBundle\Command;
use Propel\PropelBundle\Command\PhingCommand; use Propel\PropelBundle\Command\AbstractPropelCommand;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
@ -22,7 +22,7 @@ use Symfony\Component\Console\Input\InputArgument;
* *
* @author Maxime AILLOUD * @author Maxime AILLOUD
*/ */
class TableDropCommand extends PhingCommand class TableDropCommand extends AbstractPropelCommand
{ {
/** /**
* @see Command * @see Command