Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ Feat ] Include global version in Audit Command #60

Merged
merged 6 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading