Permalink
Browse files

fixed commands to work with composer

  • Loading branch information...
1 parent 1f1f598 commit a4f2266e18038caba22237b6b45e0fb9deb90bfd @miguelibero committed Jun 9, 2012
@@ -50,7 +50,8 @@ protected function initialize(InputInterface $input, OutputInterface $output)
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
- $this->getMeinhof()->setup();
+ $meinhof = $this->getMeinhof();
+ $meinhof->setup();
if ($input->getOption('update')) {
$update = new UpdateCommand();
@@ -92,8 +93,11 @@ protected function interact(InputInterface $input, OutputInterface $output)
$input->getOption('categories')), $input->getOption('categories'));
$input->setOption('categories', $categories);
- $update = $dialog->askConfirmation($output, $dialog->getQuestion('Do you want to update the site after the setup', 'yes', '?'), true);
- $input->setOption('update', $update);
+ $update = $input->getOption('update');
+ if($update !== false){
+ $update = $dialog->askConfirmation($output, $dialog->getQuestion('Do you want to update the site after the setup', 'yes', '?'), true);
+ $input->setOption('update', $update);
+ }
}
}
@@ -37,11 +37,22 @@ protected function execute(InputInterface $input, OutputInterface $output)
$meinhof = $this->getMeinhof();
if(!$meinhof->isSiteConfigured()){
$output->writeln('looks like your site needs to be set up first...');
- $command = new SetupCommand();
- $command->setHelperSet($this->getHelperSet());
- $input = new ArrayInput(array('dir' => $input->getArgument('dir')));
- $command->run($input, $output);
+ $this->runSetup($input, $output);
+ $meinhof->reload();
}
$meinhof->update();
}
+
+ protected function runSetup(InputInterface $input, OutputInterface $output)
+ {
+ $command = new SetupCommand();
+ if($helper = $this->getHelperSet()){
+ $command->setHelperSet($helper);
+ }
+ $input = new ArrayInput(array(
+ 'dir' => $input->getArgument('dir'),
+ '--update' => false,
+ ));
+ $command->run($input, $output);
+ }
}
@@ -2,9 +2,14 @@
namespace Meinhof\Composer;
-use Symfony\Component\ClassLoader\ClassCollectionLoader;
-use Symfony\Component\Process\Process;
-use Symfony\Component\Process\PhpExecutableFinder;
+use Meinhof\Command\UpdateCommand;
+
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\ArrayInput;
+use Symfony\Component\Console\Output\ConsoleOutput;
+use Symfony\Component\Console\Helper\HelperSet;
+use Symfony\Component\Console\Helper\DialogHelper;
+use Symfony\Component\Console\Helper\FormatterHelper;
/**
* The methods of this class are called
@@ -16,39 +21,47 @@ class ScriptHandler
{
public static function onInstall($event)
{
- self::executeUpdate($event);
+ try{
+ self::executeUpdate($event);
+ }catch(\Exception $e){
+ echo $e->getMessage().PHP_EOL;
+ }
}
public static function onUpdate($event)
{
- self::executeUpdate($event);
+ try{
+ self::executeUpdate($event);
+ }catch(\Exception $e){
+ echo $e->getMessage().PHP_EOL;
+ }
}
protected static function executeUpdate($event)
{
$options = self::getOptions($event);
$siteDir = $options['meinhof-site-dir'];
- if (!is_dir($siteDir)) {
- echo 'The meinhof-site-dir ('.$siteDir.') specified in composer.json was not found in '.getcwd().PHP_EOL;
- return;
- }
-
- static::executeCommand($event, $siteDir, 'update');
+ $command = new UpdateCommand();
+ self::executeCommand($command, $siteDir);
}
- protected static function executeCommand($event, $siteDir, $cmd)
+ protected static function executeCommand(Command $command, $siteDir)
{
- $phpFinder = new PhpExecutableFinder;
- $php = escapeshellarg($phpFinder->find());
- $meinhof = escapeshellarg($siteDir.'/bin/meinhof');
- if ($event->getIO()->isDecorated()) {
- $meinhof.= ' --ansi';
+ if (!is_dir($siteDir)) {
+ throw new \RuntimeException('The meinhof-site-dir ('.$siteDir.') specified in composer.json was not found in '.getcwd());
}
- $process = new Process($php.' '.$meinhof.' '.$cmd);
- $process->run(function ($type, $buffer) { echo $buffer; });
- }
+ $helpers = new HelperSet(array(
+ new FormatterHelper(),
+ new DialogHelper(),
+ ));
+
+ $command->setHelperSet($helpers);
+ $input = new ArrayInput(array('dir'=>$siteDir));
+ $output = new ConsoleOutput();
+ $command->run($input, $output);
+ }
protected static function getOptions($event)
{
View
@@ -35,6 +35,10 @@ class Meinhof
*/
protected $container;
+ protected $dir;
+ protected $input;
+ protected $output;
+
/**
* @param string $dir the path to the base of the site configuration
* @param InputInterface $Input the command line input
@@ -48,16 +52,27 @@ public function __construct($dir, InputInterface $input = null, OutputInterface
require_once($autoload);
}
- $this->container = $this->buildContainer($dir);
+ $this->dir = $dir;
+ $this->input = $input;
+ $this->output = $output;
+ $this->reload();
+
+ $this->dispatchEvent('load');
+ }
+
+ /**
+ * Reload the dependency container
+ */
+ public function reload()
+ {
+ $this->container = $this->buildContainer($this->dir);
// load input and output
- $this->container->set('input', $input);
- $this->container->set('output', $output);
+ $this->container->set('input', $this->input);
+ $this->container->set('output', $this->output);
// freeze the container
$this->container->compile();
-
- $this->dispatchEvent('load');
}
/**

0 comments on commit a4f2266

Please sign in to comment.