Skip to content

Commit 1b314ec

Browse files
[ Feat ] Include global version in Audit Command (#60)
* 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
1 parent d51a905 commit 1b314ec

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

app/Commands/Audit.php

+28-13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace ProjektGopher\Whisky\Commands;
44

5+
use Illuminate\Support\Facades\Process;
56
use LaravelZero\Framework\Commands\Command;
67
use ProjektGopher\Whisky\Platform;
78
use ProjektGopher\Whisky\Whisky;
@@ -14,26 +15,16 @@ class Audit extends Command
1415

1516
public function handle(): int
1617
{
17-
// co-pilot things. Might be useful, might not.
18-
// $this->table(
19-
// ['Hook', 'Status', 'File', 'Scripts'],
20-
// Hook::all()->map(function (Hook $hook): array {
21-
// return [
22-
// $hook->name,
23-
// $hook->status(),
24-
// $hook->file(),
25-
// $hook->scripts()->implode(PHP_EOL),
26-
// ];
27-
// })->toArray()
28-
// );
2918
$platform = new Platform();
3019

3120
$this->table(
3221
['key', 'value'],
3322
[
3423
['- Whisky -', ''],
35-
['installed globally?', Whisky::isInstalledGlobally() ? 'yes' : 'no'],
24+
['installed globally?', $this->isWhiskyInstalledGlobally()],
3625
['running globally?', Whisky::isRunningGlobally() ? 'yes' : 'no'],
26+
['installed locally?', $this->isWhiskyInstalledLocally()],
27+
['running locally?', Whisky::isRunningLocally() ? 'yes' : 'no'],
3728
['dogfooding?', Whisky::dogfooding() ? 'yes' : 'no'],
3829
['base path', Whisky::base_path()],
3930
['bin path', Whisky::bin_path()],
@@ -54,4 +45,28 @@ public function handle(): int
5445

5546
return Command::SUCCESS;
5647
}
48+
49+
protected function isWhiskyInstalledGlobally(): string
50+
{
51+
if (! Whisky::isInstalledGlobally()) {
52+
return 'no';
53+
}
54+
55+
$result = Process::run('composer global show projektgopher/whisky --format=json');
56+
$version = json_decode($result->output(), true)['versions'][0];
57+
58+
return "yes ({$version})";
59+
}
60+
61+
protected function isWhiskyInstalledLocally(): string
62+
{
63+
if (! Whisky::isInstalledLocally()) {
64+
return 'no';
65+
}
66+
67+
$result = Process::run('composer show projektgopher/whisky --format=json');
68+
$version = json_decode($result->output(), true)['versions'][0];
69+
70+
return "yes ({$version})";
71+
}
5772
}

app/Whisky.php

+10
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ public static function isRunningGlobally(): bool
4141
return str_starts_with(base_path(), 'phar://'.Platform::getGlobalComposerHome());
4242
}
4343

44+
public static function isInstalledLocally(): bool
45+
{
46+
return File::exists(Platform::cwd('vendor/projektgopher/whisky'));
47+
}
48+
49+
public static function isRunningLocally(): bool
50+
{
51+
return str_starts_with(base_path(), 'phar://'.Platform::cwd('vendor/bin'));
52+
}
53+
4454
public static function readConfig(string $key): string|array|null
4555
{
4656
$cfg = FileJson::make(Platform::cwd('whisky.json'))->read();

0 commit comments

Comments
 (0)