Skip to content
This repository has been archived by the owner on Aug 19, 2023. It is now read-only.

Commit

Permalink
Add self-update command
Browse files Browse the repository at this point in the history
  • Loading branch information
webflo committed Jul 23, 2017
1 parent c9b0d19 commit 2d22d29
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
27 changes: 26 additions & 1 deletion bin/drush.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use DrupalFinder\DrupalFinder;
use Webmozart\PathUtil\Path;
use Humbug\SelfUpdate\Updater;

set_time_limit(0);

Expand Down Expand Up @@ -31,6 +32,7 @@
$DEBUG = FALSE;
$VAR = FALSE;
$VERSION = FALSE;
$SELF_UPDATE = FALSE;

foreach ($_SERVER['argv'] as $arg) {
// If a variable to set was indicated on the
Expand All @@ -51,6 +53,9 @@
case "--version":
$VERSION = TRUE;
break;
case "self-update":
$SELF_UPDATE = TRUE;
break;
}
if (substr($arg, 0, 7) == "--root=") {
$ROOT = substr($arg, 7);
Expand All @@ -67,10 +72,30 @@

$drupalFinder = new DrupalFinder();

if ($VERSION || $DEBUG) {
if ($VERSION || $DEBUG || $SELF_UPDATE) {
echo "Drush Shim Version: {$DRUSH_SHIM_VERSION}" . PHP_EOL;
}

if ($SELF_UPDATE) {
if ($DRUSH_SHIM_VERSION === '@' . 'git-version' . '@') {
echo "Automatic update not supported.\n";
exit(1);
}
$updater = new Updater(null, false);
$updater->setStrategy(Updater::STRATEGY_GITHUB);
$updater->getStrategy()->setPackageName('webflo/drush-shim');
$updater->getStrategy()->setPharName('drush.phar');
$updater->getStrategy()->setCurrentLocalVersion($DRUSH_SHIM_VERSION);
try {
$result = $updater->update();
echo $result ? "Updated!\n" : "No update needed!\n";
exit(0);
} catch (\Exception $e) {
echo "Automatic update failed, please download the latest version from https://github.com/webflo/drush-shim/releases\n";
exit(1);
}
}

if ($DEBUG) {
echo "ROOT: " . $ROOT . PHP_EOL;
}
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"license": "GPL-2.0+",
"require": {
"webflo/drupal-finder": "^0.3.0",
"webmozart/path-util": "^2.3"
"webmozart/path-util": "^2.3",
"padraic/phar-updater": "^1.0"
},
"conflict": {
"drush/drush": "*"
Expand Down

0 comments on commit 2d22d29

Please sign in to comment.