/** * ───────────────────────────────────────────── * SPB Git — Personal Git Platform * ───────────────────────────────────────────── * Author : Simon-Pierre Boucher * Contact : contact@spboucher.ai * File : cli/commands/status.mjs * Purpose : `spbgit status` — aggregated status across workspace repos * License : MIT © Simon-Pierre Boucher * ───────────────────────────────────────────── */ import { basename, join } from 'node:path'; import { existsSync } from 'node:fs'; import pc from 'picocolors'; import { requireCliConfig } from '../lib/config.mjs'; import { workspaceRepos, repoStatus } from '../lib/git.mjs'; import { printTable, mapLimit } from '../lib/ui.mjs'; import { EXIT } from '../lib/api.mjs'; export function registerStatus(program) { program .command('status [name]') .description('aggregated status of workspace repositories') .option('--all', 'include clean repositories (default)', false) .option('--json', 'machine-readable output') .action(async (name, opts) => { const config = requireCliConfig(); let dirs = workspaceRepos(config.workspace); if (name) { const target = join(config.workspace, name); if (!existsSync(target)) { console.error(pc.red(`✗ No such workspace repo: ${name}`)); process.exit(EXIT.USER); } dirs = [target]; } if (dirs.length === 0) { console.log(pc.dim(`Workspace ${config.workspace} has no repositories. Try: spbgit clone --all`)); return; } const statuses = await mapLimit(dirs, 4, async (dir) => ({ dir, name: basename(dir), ...(await repoStatus(dir)) })); if (opts.json) { console.log(JSON.stringify(statuses, null, 2)); return; } const rows = [[pc.bold('REPO'), pc.bold('BRANCH'), pc.bold('AHEAD'), pc.bold('BEHIND'), pc.bold('DIRTY')]]; for (const s of statuses) { const clean = s.ahead === 0 && s.behind === 0 && s.dirty === 0; const paint = clean ? pc.dim : (x) => x; rows.push([ paint(s.name), paint(s.branch + (s.hasUpstream ? '' : ' (no upstream)')), s.ahead > 0 ? pc.cyan(`↑${s.ahead}`) : paint('0'), s.behind > 0 ? pc.yellow(`↓${s.behind}`) : paint('0'), s.dirty > 0 ? pc.red(String(s.dirty)) : paint('0'), ]); } printTable(rows); }); }