Skip to content

Commit

Permalink
Add new command for loading existing packages.
Browse files Browse the repository at this point in the history
Closes #9.
  • Loading branch information
franzliedke committed Mar 17, 2015
1 parent 47e0c13 commit d36ee42
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bin/studio
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require __DIR__.'/../../../autoload.php';
use Studio\Config\Config;
use Studio\Config\FileStorage;
use Studio\Console\CreateCommand;
use Studio\Console\LoadCommand;
use Studio\Console\ScrapCommand;
use Studio\Shell\TaskRunner;
use Symfony\Component\Console\Application;
Expand All @@ -17,5 +18,6 @@ $shell = new TaskRunner();

$application = new Application();
$application->add(new CreateCommand($config, $shell));
$application->add(new LoadCommand($config, $shell));
$application->add(new ScrapCommand($config, $shell));
$application->run();
69 changes: 69 additions & 0 deletions src/Console/LoadCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace Studio\Console;

use Studio\Package;
use Studio\Shell\TaskRunner;
use Studio\Config\Config;
use Symfony\Component\Console\Command\Command;
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\Question\Question;

class LoadCommand extends Command
{

protected $config;

protected $shell;


public function __construct(Config $config, TaskRunner $shell)
{
parent::__construct();

$this->config = $config;
$this->shell = $shell;
}

protected function configure()
{
$this
->setName('load')
->setDescription('Load a package to be managed with Studio')
->addArgument(
'path',
InputArgument::REQUIRED,
'The path where the package files are located'
);
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$package = Package::fromFolder($input->getArgument('path'));
$this->config->addPackage($package);

$output->writeln("<info>Package loaded successfully.</info>");

$output->writeln("<comment>Dumping autoloads...</comment>");
$this->runOnShell('composer dump-autoload');
$output->writeln("<info>Autoloads successfully generated.</info>");
}

protected function runOnShell($task, $workDir = null)
{
$process = $this->shell->process($task, $workDir);
$process->run();

if (! $process->isSuccessful()) {
$command = collect(explode(' ', $task))->first();
$error = $process->getErrorOutput();
throw new \RuntimeException("Error while running $command: $error");
}

return $process->getOutput();
}

}

0 comments on commit d36ee42

Please sign in to comment.