Skip to content

Commit

Permalink
Add more version information
Browse files Browse the repository at this point in the history
  • Loading branch information
mischabraam committed Mar 19, 2024
1 parent 3fe77a2 commit 09431b2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
17 changes: 11 additions & 6 deletions cli/ValetPlus/Extended/Valet.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@

namespace WeProvide\ValetPlus\Extended;

use GuzzleHttp\Client;
use Valet\Valet as ValetValet;

class Valet extends ValetValet
{
/**
* @todo: check if this is needed
* Symlink the Valet Bash script into the user's local bin.
* Determine if this is the latest version of Valet+.
*
* @param string $currentVersion
* @return bool
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function symlinkToUsersBin(): void
public function onLatestPlusVersion(string $currentVersion): bool
{
// $this->unlinkFromUsersBin();
//
// $this->cli->runAsUser('ln -s "' . realpath(__DIR__ . '/../../../valet') . '" ' . $this->valetBin);
$url = 'https://api.github.com/repos/weprovide/valet-plus/releases/latest';
$response = json_decode((string) (new Client())->get($url)->getBody());

return version_compare($currentVersion, trim($response->tag_name, 'v'), '>=');
}
}
27 changes: 25 additions & 2 deletions cli/valet.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env php
<?php

use Silly\Application;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -25,9 +26,14 @@


// Change name and version.
$app->setName('Valet+');
$app->setVersion('3.0.1');
/** @var Application $app */
$laravelValetName = $app->getName();
$laravelValetVersion = $app->getVersion();
$valetPlusName = 'Valet+';
$valetPlusVersion = '3.0.1';

$app->setVersion($laravelValetName . ' ' . $laravelValetVersion);
$app->setName(' ' . $valetPlusName . ' ' . $valetPlusVersion . "\n");

/**
* Extend the 'install' command.
Expand Down Expand Up @@ -88,6 +94,23 @@
* Most commands are available only if Valet+ is installed.
*/
if (is_dir(VALET_HOME_PATH)) {
/**
* Extend the 'on-latest-version' command.
*/
$cmd = $app->get('on-latest-version');
$app->command('on-latest-version', function (InputInterface $input, OutputInterface $output) use ($cmd, $valetPlusVersion) {
output('On latest Valet+ version?');
if (Valet::onLatestPlusVersion($valetPlusVersion)) {
output('Yes');
} else {
output(sprintf('Your version of Valet+ (%s) is not the latest version available.', $valetPlusVersion));
}

output('');
output('On latest Laravel Valet version?');
$cmd->run($input, $output);
}, ['latest'])->descriptions('Determine if this is the latest version of Valet+ and Laravel Valet');

/**
* Extend the 'tld' command.
*/
Expand Down

0 comments on commit 09431b2

Please sign in to comment.