option('root') ?: storage_path('documents'); $dryRun = (bool) $this->option('dry-run'); $this->info('Document Manager folder synchronisation'); $this->line('Root path: ' . $rootPath); $this->line($dryRun ? 'Mode: Dry run (no directories will be created)' : 'Mode: Live'); $this->newLine(); if (! File::isDirectory($rootPath)) { if ($dryRun) { $this->warn('Documents directory does not exist. (dry-run)'); } else { File::ensureDirectoryExists($rootPath); $this->info('Created documents root directory.'); } } $results = $catalog->sync($rootPath, $dryRun); if (! empty($results['created'])) { $title = $dryRun ? 'Directories that would be created' : 'Directories created'; $this->section($title); $this->displayList($results['created']); $this->newLine(); } if (! empty($results['existing'])) { $this->section('Directories already present'); $this->displayList($results['existing']); $this->newLine(); } // Detect directories that are not part of the catalog $extras = $catalog->detectExtra($rootPath); if ($extras->isNotEmpty()) { $this->section('Directories not defined in the catalog'); $sorted = $extras->sort()->values(); $this->displayList($sorted->all()); $this->newLine(); } $this->info('Document Manager folder synchronisation completed.'); if ($dryRun) { $this->comment('Dry run mode - no changes were applied.'); } return self::SUCCESS; } protected function section(string $title): void { $this->line('' . $title . ''); } protected function displayList(array $items, int $limit = 20): void { $items = array_values(array_unique($items)); $total = count($items); $display = array_slice($items, 0, $limit); foreach ($display as $item) { $this->line(' - ' . $item); } if ($total > $limit) { $this->line(' ... ' . ($total - $limit) . ' more'); } } }