/** * ───────────────────────────────────────────── * SPB Git — Personal Git Platform * ───────────────────────────────────────────── * Author : Simon-Pierre Boucher * Contact : contact@spboucher.ai * File : cli/commands/open.mjs * Purpose : `spbgit open [name]` — open the web UI in the browser * License : MIT © Simon-Pierre Boucher * ───────────────────────────────────────────── */ import { execFile } from 'node:child_process'; import { platform } from 'node:os'; import pc from 'picocolors'; import { requireCliConfig } from '../lib/config.mjs'; export function registerOpen(program) { program .command('open [name]') .description('open the repo page (or home) in the default browser') .action((name) => { const config = requireCliConfig(); const url = name ? `${config.server}/${name}` : config.server; const opener = platform() === 'darwin' ? 'open' : platform() === 'win32' ? 'start' : 'xdg-open'; execFile(opener, [url], (err) => { if (err) console.error(pc.red(`✗ Could not open browser: ${err.message}\n URL: ${url}`)); else console.log(`${pc.green('✓')} ${url}`); }); }); }