environment(['local', 'development', 'testing']) && ! $this->option('force')) { $this->error('This command is intended for development only. Use --force to override.'); return self::FAILURE; } $team = Team::query()->find((int) $this->option('team-id')) ?? Team::query()->orderBy('id')->first(); $user = User::query()->find((int) $this->option('user-id')) ?? User::query()->orderBy('id')->first(); $privateKeyId = $this->option('private-key-id'); $privateKey = is_numeric($privateKeyId) ? PrivateKey::query()->find((int) $privateKeyId) : PrivateKey::query() ->where('team_id', $team?->id) ->where('is_git_related', false) ->orderBy('id') ->first(); if (! $team instanceof Team || ! $user instanceof User) { $this->warn('Cannot sync dev Lima servers without an existing team and user.'); return self::SUCCESS; } $servers = $this->option('server'); if (! is_array($servers) || $servers === []) { $this->warn('No dev Lima servers were provided.'); return self::SUCCESS; } $cluster = Cluster::query()->updateOrCreate([ 'team_id' => $team->id, 'name' => (string) $this->option('cluster'), ], [ 'created_by_user_id' => $user->id, 'description' => 'Local Lima development cluster managed by scripts/dev.sh.', ]); $builderCapacity = max(0, (int) $this->option('builder-capacity')); $builderEnabled = $builderCapacity > 0; $capabilities = $builderEnabled ? ['coold', 'builder'] : ['coold']; foreach ($servers as $server) { $parts = explode('|', (string) $server); if (count($parts) !== 4) { $this->error("Invalid server '{$server}'. Expected name|host|ssh_user|ssh_port."); return self::FAILURE; } [$name, $host, $sshUser, $sshPort] = $parts; Server::query()->updateOrCreate([ 'team_id' => $team->id, 'cluster_id' => $cluster->id, 'name' => $name, ], [ 'created_by_user_id' => $user->id, 'private_key_id' => $privateKey?->id, 'host' => $host, 'ssh_user' => $sshUser, 'ssh_port' => (int) $sshPort, 'status' => 'installed', 'capabilities' => $capabilities, 'builder_enabled' => $builderEnabled, 'builder_capacity' => $builderCapacity, 'last_bootstrapped_at' => now(), ]); $this->info("Synced {$name} ({$host}:{$sshPort})."); } return self::SUCCESS; } }