(_program: Command)
| 36 | } |
| 37 | |
| 38 | export function createConvertAction(_program: Command): (inputPath: string, options: ConvertOptions) => Promise<void> { |
| 39 | return async (inputPath, options) => { |
| 40 | try { |
| 41 | debug(`Converting: ${inputPath}`) |
| 42 | debug(`Options: ${JSON.stringify(options)}`) |
| 43 | const result = await convertFile(inputPath, options) |
| 44 | |
| 45 | // Handle --open flag: open the converted .deepnote file in Deepnote Cloud |
| 46 | if (options.open) { |
| 47 | const c = getChalk() |
| 48 | if (result.outputFormat !== 'deepnote') { |
| 49 | output(c.yellow('Warning: --open is only available when converting to .deepnote format')) |
| 50 | } else if (result.outputIsDirectory) { |
| 51 | output( |
| 52 | c.yellow( |
| 53 | 'Warning: --open is not supported when converting a directory; open a file with `deepnote open <file>`' |
| 54 | ) |
| 55 | ) |
| 56 | } else { |
| 57 | const quiet = getOutputConfig().quiet |
| 58 | const openResult = await openDeepnoteFileInCloud(result.outputPath, { quiet }) |
| 59 | if (!quiet) { |
| 60 | output(`${c.green('✓')} Opened in Deepnote Cloud`) |
| 61 | output(`${c.dim('URL:')} ${openResult.url}`) |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | } catch (error) { |
| 66 | const message = error instanceof Error ? error.message : String(error) |
| 67 | logError(message) |
| 68 | process.exit(ExitCode.Error) |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | async function convertFile(inputPath: string, options: ConvertOptions): Promise<ConvertResult> { |
| 74 | const { absolutePath, isDirectory, extension: ext } = await resolvePath(inputPath) |
no test coverage detected