diff --git a/bin/studio b/bin/studio index 87076ad..dc9cfa4 100755 --- a/bin/studio +++ b/bin/studio @@ -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; @@ -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(); diff --git a/src/Console/LoadCommand.php b/src/Console/LoadCommand.php new file mode 100644 index 0000000..114b1d6 --- /dev/null +++ b/src/Console/LoadCommand.php @@ -0,0 +1,69 @@ +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("Package loaded successfully."); + + $output->writeln("Dumping autoloads..."); + $this->runOnShell('composer dump-autoload'); + $output->writeln("Autoloads successfully generated."); + } + + 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(); + } + +}