feat: multiselect removable resources

This commit is contained in:
Andras Bacsai 2023-10-04 14:40:04 +02:00
parent 1651845e20
commit 38e1f17edf

View File

@ -8,6 +8,7 @@ use App\Models\StandalonePostgresql;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use function Laravel\Prompts\confirm; use function Laravel\Prompts\confirm;
use function Laravel\Prompts\multiselect;
use function Laravel\Prompts\select; use function Laravel\Prompts\select;
class ResourcesDelete extends Command class ResourcesDelete extends Command
@ -50,16 +51,18 @@ class ResourcesDelete extends Command
$this->error('There are no applications to delete.'); $this->error('There are no applications to delete.');
return; return;
} }
$application = select( $applicationsToDelete = multiselect(
'What application do you want to delete?', 'What application do you want to delete?',
$applications->pluck('name')->toArray(), $applications->pluck('name')->toArray(),
); );
$application = $applications->where('name', $application)->first(); $confirmed = confirm("Are you sure you want to delete all selected resources?");
$confirmed = confirm("Are you sure you want to delete {$application->name}?");
if (!$confirmed) { if (!$confirmed) {
return; return;
} }
$application->delete(); foreach ($applicationsToDelete as $application) {
$toDelete = $applications->where('name', $application)->first();
$toDelete->delete();
}
} }
private function deleteDatabase() private function deleteDatabase()
{ {
@ -68,16 +71,19 @@ class ResourcesDelete extends Command
$this->error('There are no databases to delete.'); $this->error('There are no databases to delete.');
return; return;
} }
$database = select( $databasesToDelete = multiselect(
'What database do you want to delete?', 'What database do you want to delete?',
$databases->pluck('name')->toArray(), $databases->pluck('name')->toArray(),
); );
$database = $databases->where('name', $database)->first(); $confirmed = confirm("Are you sure you want to delete all selected resources?");
$confirmed = confirm("Are you sure you want to delete {$database->name}?");
if (!$confirmed) { if (!$confirmed) {
return; return;
} }
$database->delete(); foreach ($databasesToDelete as $database) {
$toDelete = $databases->where('name', $database)->first();
$toDelete->delete();
}
} }
private function deleteService() private function deleteService()
{ {
@ -86,15 +92,17 @@ class ResourcesDelete extends Command
$this->error('There are no services to delete.'); $this->error('There are no services to delete.');
return; return;
} }
$service = select( $servicesToDelete = multiselect(
'What service do you want to delete?', 'What service do you want to delete?',
$services->pluck('name')->toArray(), $services->pluck('name')->toArray(),
); );
$service = $services->where('name', $service)->first(); $confirmed = confirm("Are you sure you want to delete all selected resources?");
$confirmed = confirm("Are you sure you want to delete {$service->name}?");
if (!$confirmed) { if (!$confirmed) {
return; return;
} }
$service->delete(); foreach ($servicesToDelete as $service) {
$toDelete = $services->where('name', $service)->first();
$toDelete->delete();
}
} }
} }