Skip to content

Commit

Permalink
Add checks to resource command to make sure CLI is setup
Browse files Browse the repository at this point in the history
  • Loading branch information
jonerickson committed Aug 13, 2023
1 parent 2b9d9fb commit bd88415
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ jobs:
- name: Build Bundle
run: php perscom app:build perscom --build-version=${{ steps.tag_version.outputs.new_tag }} -vvv

- name: Update Permissions
run: chmod +x builds/perscom

- name: Create Github Release
uses: ncipollo/release-action@v1
if: github.ref == 'refs/heads/master'
Expand Down
2 changes: 1 addition & 1 deletion app/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function handle()
});
}

$found = Setting::query()->whereIn('key', ['perscom_id', 'api_key'])->exists();
$found = Setting::query()->whereIn('key', ['perscom_id', 'api_key'])->whereNotNull('value')->exists();

$continue = true;
if ($found) {
Expand Down
14 changes: 14 additions & 0 deletions app/Commands/ResourceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use App\Contracts\PerscomApiServiceContract;
use App\Contracts\ResourceCommandContract;
use App\Models\Setting;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use function Termwind\render;

abstract class ResourceCommand extends Command implements ResourceCommandContract
Expand All @@ -16,6 +18,18 @@ abstract class ResourceCommand extends Command implements ResourceCommandContrac
*/
public function handle()
{
if (! File::exists($_SERVER['HOME'].'/.perscom/database.sqlite')) {
$this->error('Unable to find the local database. Please run the install command to perform the PERSCOM CLI setup.');

return Command::FAILURE;
}

if (! Setting::query()->whereIn('key', ['perscom_id', 'api_key'])->whereNotNull('value')->exists()) {
$this->error('Unable to load saved PERSCOM credentials. Please run the install command to perform the PERSCOM CLI setup.');

return Command::FAILURE;
}

$apiService = app()->make(PerscomApiServiceContract::class);

$response = $apiService->api(optional($this->option('id'), function ($id) {
Expand Down
2 changes: 1 addition & 1 deletion config/logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

'stderr' => [
'driver' => 'monolog',
'level' => env('LOG_LEVEL', 'debug'),
'level' => env('LOG_LEVEL', 'error'),
'handler' => StreamHandler::class,
'formatter' => env('LOG_STDERR_FORMATTER'),
'with' => [
Expand Down

0 comments on commit bd88415

Please sign in to comment.