(getConfig: () => Config)
| 355 | } |
| 356 | |
| 357 | export function cloneCommand(getConfig: () => Config): Command { |
| 358 | return new Command('clone') |
| 359 | .description('Clone a git repository and open it') |
| 360 | .argument('<url>', 'Repository URL or owner/repo shorthand') |
| 361 | .argument('[dir]', 'Target directory (default: ./<repo-name>)') |
| 362 | .option('--json', 'Output JSONL progress events', false) |
| 363 | .option('-b, --branch <branch>', 'Branch to check out (falls back to default if missing)') |
| 364 | .action( |
| 365 | async (url: string, dir: string | undefined, opts: { json: boolean; branch?: string }) => { |
| 366 | const config = getConfig(); |
| 367 | try { |
| 368 | const targetDir = await runClone( |
| 369 | url, |
| 370 | { json: opts.json, dir, branch: opts.branch ?? null }, |
| 371 | config, |
| 372 | ); |
| 373 | if (opts.json) { |
| 374 | emit(true, { type: 'complete', dir: targetDir }); |
| 375 | } else { |
| 376 | process.stderr.write(`✓ Cloned to ${targetDir}\n`); |
| 377 | process.chdir(targetDir); |
| 378 | const { startCommand } = await import('./start.ts'); |
| 379 | const startCmd = startCommand(getConfig); |
| 380 | await startCmd.parseAsync([], { from: 'user' }); |
| 381 | } |
| 382 | } catch (err) { |
| 383 | if (err instanceof GitNotAvailableError || err instanceof GitTooOldError) { |
| 384 | if (opts.json) { |
| 385 | emit(true, { type: 'error', message: err.message }); |
| 386 | } else { |
| 387 | process.stderr.write(`${err.message}\n`); |
| 388 | } |
| 389 | process.exitCode = 78; |
| 390 | return; |
| 391 | } |
| 392 | await handleCloneFailure({ |
| 393 | error: err, |
| 394 | url, |
| 395 | branch: opts.branch ?? null, |
| 396 | json: opts.json, |
| 397 | emit: (event) => emit(true, event), |
| 398 | printStderr: (text) => process.stderr.write(text), |
| 399 | }); |
| 400 | process.exitCode = 1; |
| 401 | } |
| 402 | }, |
| 403 | ); |
| 404 | } |
no test coverage detected