Skip to content

Commit

Permalink
[ Feat ] Include global version in Audit Command (#60)
Browse files Browse the repository at this point in the history
* remove comment

* get global version from composer instead of filesystem

* add methods for local install

* add local install info to audit command

* get locally installed version number
  • Loading branch information
ProjektGopher authored May 24, 2024
1 parent d51a905 commit 1b314ec
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
41 changes: 28 additions & 13 deletions app/Commands/Audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ProjektGopher\Whisky\Commands;

use Illuminate\Support\Facades\Process;
use LaravelZero\Framework\Commands\Command;
use ProjektGopher\Whisky\Platform;
use ProjektGopher\Whisky\Whisky;
Expand All @@ -14,26 +15,16 @@ class Audit extends Command

public function handle(): int
{
// co-pilot things. Might be useful, might not.
// $this->table(
// ['Hook', 'Status', 'File', 'Scripts'],
// Hook::all()->map(function (Hook $hook): array {
// return [
// $hook->name,
// $hook->status(),
// $hook->file(),
// $hook->scripts()->implode(PHP_EOL),
// ];
// })->toArray()
// );
$platform = new Platform();

$this->table(
['key', 'value'],
[
['- Whisky -', ''],
['installed globally?', Whisky::isInstalledGlobally() ? 'yes' : 'no'],
['installed globally?', $this->isWhiskyInstalledGlobally()],
['running globally?', Whisky::isRunningGlobally() ? 'yes' : 'no'],
['installed locally?', $this->isWhiskyInstalledLocally()],
['running locally?', Whisky::isRunningLocally() ? 'yes' : 'no'],
['dogfooding?', Whisky::dogfooding() ? 'yes' : 'no'],
['base path', Whisky::base_path()],
['bin path', Whisky::bin_path()],
Expand All @@ -54,4 +45,28 @@ public function handle(): int

return Command::SUCCESS;
}

protected function isWhiskyInstalledGlobally(): string
{
if (! Whisky::isInstalledGlobally()) {
return 'no';
}

$result = Process::run('composer global show projektgopher/whisky --format=json');
$version = json_decode($result->output(), true)['versions'][0];

return "yes ({$version})";
}

protected function isWhiskyInstalledLocally(): string
{
if (! Whisky::isInstalledLocally()) {
return 'no';
}

$result = Process::run('composer show projektgopher/whisky --format=json');
$version = json_decode($result->output(), true)['versions'][0];

return "yes ({$version})";
}
}
10 changes: 10 additions & 0 deletions app/Whisky.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ public static function isRunningGlobally(): bool
return str_starts_with(base_path(), 'phar://'.Platform::getGlobalComposerHome());
}

public static function isInstalledLocally(): bool
{
return File::exists(Platform::cwd('vendor/projektgopher/whisky'));
}

public static function isRunningLocally(): bool
{
return str_starts_with(base_path(), 'phar://'.Platform::cwd('vendor/bin'));
}

public static function readConfig(string $key): string|array|null
{
$cfg = FileJson::make(Platform::cwd('whisky.json'))->read();
Expand Down

0 comments on commit 1b314ec

Please sign in to comment.