|
| 1 | +import chalk from 'chalk' |
| 2 | +import { Command } from 'commander' |
| 3 | +import { createInspectAction } from './commands/inspect' |
| 4 | +import { version } from './version' |
| 5 | + |
| 6 | +/** |
| 7 | + * Creates and configures the main CLI program. |
| 8 | + */ |
| 9 | +export function createProgram(): Command { |
| 10 | + const program = new Command() |
| 11 | + |
| 12 | + program |
| 13 | + .name('deepnote') |
| 14 | + .description(getWelcomeText()) |
| 15 | + .version(version, '-v, --version', 'Display the CLI version') |
| 16 | + .helpOption('-h, --help', 'Display help information') |
| 17 | + .showHelpAfterError(false) |
| 18 | + .configureOutput({ |
| 19 | + // Write errors to stderr with chalk styling |
| 20 | + outputError: (str, write) => write(chalk.red(str)), |
| 21 | + }) |
| 22 | + |
| 23 | + // Register placeholder commands (to be implemented in future phases) |
| 24 | + registerCommands(program) |
| 25 | + |
| 26 | + return program |
| 27 | +} |
| 28 | + |
| 29 | +/** |
| 30 | + * Registers all available commands on the program. |
| 31 | + */ |
| 32 | +function registerCommands(program: Command): void { |
| 33 | + // Inspect command - for inspecting and displaying .deepnote file metadata |
| 34 | + program |
| 35 | + .command('inspect') |
| 36 | + .description('Inspect and display metadata from a .deepnote file') |
| 37 | + .argument('<path>', 'Path to .deepnote file') |
| 38 | + .action(createInspectAction(program)) |
| 39 | +} |
| 40 | + |
| 41 | +/** |
| 42 | + * Returns the welcome text displayed in help output. |
| 43 | + */ |
| 44 | +function getWelcomeText(): string { |
| 45 | + return `${chalk.bold.cyan('Deepnote CLI')} - Run Deepnote projects from the command line |
| 46 | +
|
| 47 | +${chalk.dim('Run .deepnote files locally or on Deepnote Cloud for data science workflows,')} |
| 48 | +${chalk.dim('automation, CI/CD pipelines, and interactive development.')} |
| 49 | +
|
| 50 | +${chalk.dim('Documentation:')} ${chalk.underline('https://deepnote.com/docs/getting-started')} |
| 51 | +${chalk.dim('Repository:')} ${chalk.underline('https://github.com/deepnote/deepnote')}` |
| 52 | +} |
| 53 | + |
| 54 | +/** |
| 55 | + * Parses command line arguments and runs the CLI. |
| 56 | + * This is the main entry point for the CLI. |
| 57 | + */ |
| 58 | +export function run(argv?: string[]): void { |
| 59 | + const program = createProgram() |
| 60 | + program.parse(argv ?? process.argv) |
| 61 | +} |
0 commit comments