Skip to content

Commit

Permalink
consolidation#497 Fix: Add Basic Self Update Functionality: Inject Re…
Browse files Browse the repository at this point in the history
…po from /robo

- Inject Repo from the base controller /robo file
- Space text fix
  • Loading branch information
amenk committed Sep 3, 2017
1 parent 8edc5f2 commit 9697fe6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions robo
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ if (strpos(basename(__FILE__), 'phar')) {
}
}
$runner = new \Robo\Runner();
$runner->setSelfUpdateRepository('consolidation/robo');
$statusCode = $runner->execute($_SERVER['argv']);
exit($statusCode);
14 changes: 10 additions & 4 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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);
}
}
22 changes: 22 additions & 0 deletions src/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class Runner implements ContainerAwareInterface
*/
protected $errorConditions = [];

/**
* @var string GitHub Repo for SelfUpdate
*/
protected $selfUpdateRepository = null;

/**
* Class Constructor
*
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/SelfUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 9697fe6

Please sign in to comment.