(
selector: StoreSelectorOptions,
output: {
json?: boolean;
failurePayload?: Record<string, unknown>;
/** Diagnostic commands inspect what exists; they never scaffold. */
allowImplicitRoot?: boolean;
} = {}
)
| 474 | * standard error handling so message text and exit behavior stay consistent. |
| 475 | */ |
| 476 | export async function resolveRootForCommand( |
| 477 | selector: StoreSelectorOptions, |
| 478 | output: { |
| 479 | json?: boolean; |
| 480 | failurePayload?: Record<string, unknown>; |
| 481 | /** Diagnostic commands inspect what exists; they never scaffold. */ |
| 482 | allowImplicitRoot?: boolean; |
| 483 | } = {} |
| 484 | ): Promise<ResolvedOpenSpecRoot | null> { |
| 485 | try { |
| 486 | const root = await resolveOpenSpecRoot({ |
| 487 | ...(selector.store !== undefined ? { store: selector.store } : {}), |
| 488 | ...(selector.storePath !== undefined ? { storePath: selector.storePath } : {}), |
| 489 | ...(output.allowImplicitRoot !== undefined |
| 490 | ? { allowImplicitRoot: output.allowImplicitRoot } |
| 491 | : {}), |
| 492 | }); |
| 493 | |
| 494 | // Emitted at resolution time so the banner survives command failures |
| 495 | // that happen after the root was successfully selected. |
| 496 | if (!output.json) { |
| 497 | emitStoreRootBanner(root); |
| 498 | } |
| 499 | |
| 500 | return root; |
| 501 | } catch (error) { |
| 502 | if (output.json && isRootSelectionError(error)) { |
| 503 | console.log( |
| 504 | JSON.stringify( |
| 505 | { ...(output.failurePayload ?? {}), status: [error.diagnostic] }, |
| 506 | null, |
| 507 | 2 |
| 508 | ) |
| 509 | ); |
| 510 | process.exitCode = 1; |
| 511 | return null; |
| 512 | } |
| 513 | |
| 514 | throw error; |
| 515 | } |
| 516 | } |
no test coverage detected