| 60 | } |
| 61 | |
| 62 | export async function handleExport( |
| 63 | deps: ExportDeps, |
| 64 | sessionId: string | undefined, |
| 65 | output: string | undefined, |
| 66 | opts: ExportOptions, |
| 67 | ): Promise<void> { |
| 68 | const requestedId = normalizeOptionalSessionId(sessionId); |
| 69 | const previousSummary = requestedId === undefined ? await findPreviousSession(deps) : undefined; |
| 70 | |
| 71 | let resolvedId: string; |
| 72 | if (requestedId !== undefined) { |
| 73 | resolvedId = requestedId; |
| 74 | } else { |
| 75 | if (previousSummary === undefined) { |
| 76 | deps.stderr.write('No previous session found to export.\n'); |
| 77 | deps.exit(1); |
| 78 | } |
| 79 | resolvedId = previousSummary.id; |
| 80 | if (!opts.yes) { |
| 81 | const confirmed = await deps.confirmPreviousSession(toPreviousSessionSummary(previousSummary)); |
| 82 | if (!confirmed) { |
| 83 | deps.stdout.write('Export cancelled.\n'); |
| 84 | return; |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | try { |
| 90 | const installSource = await deps.getInstallSource(); |
| 91 | const shellEnv = deps.getShellEnv(); |
| 92 | const result = await deps.exportSession({ |
| 93 | id: resolvedId, |
| 94 | version: deps.version, |
| 95 | installSource, |
| 96 | shellEnv, |
| 97 | ...(output === undefined ? {} : { outputPath: output }), |
| 98 | ...(opts.includeGlobalLog ? { includeGlobalLog: true } : {}), |
| 99 | }); |
| 100 | deps.stdout.write(`${result.zipPath}\n`); |
| 101 | } catch (error) { |
| 102 | deps.stderr.write(`${errorMessage(error)}\n`); |
| 103 | deps.exit(1); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | export function registerExportCommand(parent: Command, deps?: Partial<ExportDeps>): void { |
| 108 | parent |