( _program: Command )
| 10 | } |
| 11 | |
| 12 | export function createInspectAction( |
| 13 | _program: Command |
| 14 | ): (path: string | undefined, options: InspectOptions) => Promise<void> { |
| 15 | return async (path, options) => { |
| 16 | try { |
| 17 | debug(`Inspecting file: ${path}`) |
| 18 | debug(`Options: ${JSON.stringify(options)}`) |
| 19 | await inspectDeepnoteFile(path, options) |
| 20 | } catch (error) { |
| 21 | const message = error instanceof Error ? error.message : String(error) |
| 22 | // Use InvalidUsage for file resolution and parse errors (user input), Error for runtime failures |
| 23 | const exitCode = |
| 24 | error instanceof FileResolutionError || error instanceof ParseError ? ExitCode.InvalidUsage : ExitCode.Error |
| 25 | if (options.output === 'json') { |
| 26 | outputJson({ success: false, error: message }) |
| 27 | } else if (options.output === 'toon') { |
| 28 | outputToon({ success: false, error: message }) |
| 29 | } else { |
| 30 | logError(message) |
| 31 | } |
| 32 | process.exit(exitCode) |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | async function inspectDeepnoteFile(path: string | undefined, options: InspectOptions): Promise<void> { |
| 38 | const { absolutePath } = await resolvePathToDeepnoteFile(path) |
no test coverage detected