option('force'); $merge = $this->option('merge'); $defaultsPath = config_path('settings/defaults.json'); // defaults.json 파일 존재 확인 if (! File::exists($defaultsPath)) { $this->error("기본 설정 파일을 찾을 수 없습니다: {$defaultsPath}"); $this->error('config/settings/defaults.json 파일이 존재하는지 확인하세요.'); return Command::FAILURE; } // defaults.json 로드 $content = File::get($defaultsPath); $data = json_decode($content, true); if (json_last_error() !== JSON_ERROR_NONE) { $this->error('기본 설정 파일 JSON 파싱 실패: '.json_last_error_msg()); return Command::FAILURE; } $defaults = $data['defaults'] ?? []; $categories = $data['_meta']['categories'] ?? []; if (empty($defaults)) { $this->error('기본 설정 파일에 defaults 섹션이 없습니다.'); return Command::FAILURE; } $this->info('환경설정 설치를 시작합니다...'); $this->newLine(); $installedCount = 0; $skippedCount = 0; $mergedCount = 0; foreach ($categories as $category) { $categoryDefaults = $defaults[$category] ?? []; if (empty($categoryDefaults)) { $this->warn(" [{$category}] 기본값이 없습니다. 건너뜁니다."); continue; } $settingsPath = storage_path("app/settings/{$category}.json"); $exists = File::exists($settingsPath); if ($exists && ! $force && ! $merge) { $this->line(" [{$category}] 이미 존재합니다. 건너뜁니다. (--force 또는 --merge 옵션 사용)"); $skippedCount++; continue; } if ($exists && $merge) { // 병합 모드: 기존 설정과 병합 (기존 값 유지, 새 키만 추가) $existingSettings = $this->configRepository->getCategory($category); $mergedSettings = array_merge($categoryDefaults, $existingSettings); if ($this->configRepository->saveCategory($category, $mergedSettings)) { $newKeysCount = count(array_diff_key($categoryDefaults, $existingSettings)); $this->info(" [{$category}] 병합 완료 ({$newKeysCount}개 새 키 추가)"); $mergedCount++; } else { $this->error(" [{$category}] 병합 실패"); } continue; } // 새로 설치 또는 덮어쓰기 if ($this->configRepository->saveCategory($category, $categoryDefaults)) { $action = $exists ? '덮어씀' : '설치됨'; $this->info(" [{$category}] {$action}"); $installedCount++; } else { $this->error(" [{$category}] 설치 실패"); } } $this->newLine(); $this->info('환경설정 설치 완료!'); $this->line(" - 설치됨: {$installedCount}개"); $this->line(" - 병합됨: {$mergedCount}개"); $this->line(" - 건너뜀: {$skippedCount}개"); return Command::SUCCESS; } }