(_program: Command)
| 41 | } |
| 42 | |
| 43 | export function createCatAction(_program: Command): (path: string, options: CatOptions) => Promise<void> { |
| 44 | return async (path, options) => { |
| 45 | try { |
| 46 | debug(`Cat file: ${path}`) |
| 47 | debug(`Options: ${JSON.stringify(options)}`) |
| 48 | await catDeepnoteFile(path, options) |
| 49 | } catch (error) { |
| 50 | const message = error instanceof Error ? error.message : String(error) |
| 51 | // User input errors should return InvalidUsage (2) |
| 52 | const exitCode = |
| 53 | error instanceof FileResolutionError || error instanceof ParseError || error instanceof NotFoundInProjectError |
| 54 | ? ExitCode.InvalidUsage |
| 55 | : ExitCode.Error |
| 56 | if (options.output === 'json') { |
| 57 | outputJson({ success: false, error: message }) |
| 58 | } else { |
| 59 | logError(message) |
| 60 | } |
| 61 | process.exit(exitCode) |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | async function catDeepnoteFile(path: string, options: CatOptions): Promise<void> { |
| 67 | const { absolutePath } = await resolvePathToDeepnoteFile(path) |
no test coverage detected