From 9697fe6ed519ed7ca26a184420e718c6deabb8a3 Mon Sep 17 00:00:00 2001 From: Alexander Menk Date: Sun, 3 Sep 2017 17:16:02 +0200 Subject: [PATCH] #497 Fix: Add Basic Self Update Functionality: Inject Repo from /robo - Inject Repo from the base controller /robo file - Space text fix --- robo | 1 + src/Application.php | 14 ++++++++++---- src/Runner.php | 22 ++++++++++++++++++++++ src/SelfUpdateCommand.php | 2 +- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/robo b/robo index ce4d9dfab..2093bd119 100755 --- a/robo +++ b/robo @@ -17,5 +17,6 @@ if (strpos(basename(__FILE__), 'phar')) { } } $runner = new \Robo\Runner(); +$runner->setSelfUpdateRepository('consolidation/robo'); $statusCode = $runner->execute($_SERVER['argv']); exit($statusCode); diff --git a/src/Application.php b/src/Application.php index 47f7e748f..3b9b06475 100644 --- a/src/Application.php +++ b/src/Application.php @@ -28,8 +28,6 @@ public function __construct($name, $version) ->addOption( new InputOption('--define', '-D', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Define a configuration item value.', []) ); - - $this->addSelfUpdateCommand(); } /** @@ -59,9 +57,17 @@ public function addInitRoboFileCommand($roboFile, $roboClass) $this->add($createRoboFile); } - protected function addSelfUpdateCommand() + /** + * Add self update command, do nothing if null is provided + * + * @param string $repository GitHub Repository for self update + */ + public function addSelfUpdateCommand($repository = null) { - $selfUpdateCommand = new SelfUpdateCommand('self:update', Robo::VERSION, 'consolidation/robo'); + if ($repository == null) { + return; + } + $selfUpdateCommand = new SelfUpdateCommand('self:update', Robo::VERSION, $repository); $this->add($selfUpdateCommand); } } diff --git a/src/Runner.php b/src/Runner.php index 529656fbb..913452358 100644 --- a/src/Runner.php +++ b/src/Runner.php @@ -38,6 +38,11 @@ class Runner implements ContainerAwareInterface */ protected $errorConditions = []; + /** + * @var string GitHub Repo for SelfUpdate + */ + protected $selfUpdateRepository = null; + /** * Class Constructor * @@ -155,6 +160,7 @@ public function run($input = null, $output = null, $app = null, $commandFiles = if (!$app) { $app = Robo::application(); + $app->addSelfUpdateCommand($this->getSelfUpdateRepository()); } if (!isset($commandFiles)) { $this->errorCondtion("Robo is not initialized here. Please run `robo init` to create a new RoboFile.", 'yellow'); @@ -438,4 +444,20 @@ public function handleError() } return false; } + + /** + * @return string + */ + public function getSelfUpdateRepository() + { + return $this->selfUpdateRepository; + } + + /** + * @param string $selfUpdateRepository + */ + public function setSelfUpdateRepository($selfUpdateRepository) + { + $this->selfUpdateRepository = $selfUpdateRepository; + } } diff --git a/src/SelfUpdateCommand.php b/src/SelfUpdateCommand.php index 98190038a..87f8c8f56 100644 --- a/src/SelfUpdateCommand.php +++ b/src/SelfUpdateCommand.php @@ -120,7 +120,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $fs = new sfFilesystem(); - $output->writeln('Downloading ' . Robo::APPLICATION_NAME . ' (' . $this->gitHubRepository . ')' . $latest); + $output->writeln('Downloading ' . Robo::APPLICATION_NAME . ' (' . $this->gitHubRepository . ') ' . $latest); $fs->copy($downloadUrl, $tempFilename);