MCPcopy
hub / github.com/deepnote/deepnote / createProgram

Function createProgram

packages/cli/src/cli.ts:42–146  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40 * Creates and configures the main CLI program.
41 */
42export function createProgram(): Command {
43 const program = new Command()
44
45 program
46 .name('deepnote')
47 .description(getWelcomeText())
48 .version(version, '-v, --version', 'Display the CLI version')
49 .helpOption('-h, --help', 'Display help information')
50 .showHelpAfterError(false)
51 .configureOutput({
52 // Write errors to stderr with chalk styling
53 outputError: (str, write) => write(chalk.red(str)),
54 })
55 .exitOverride(err => {
56 // Map Commander errors to appropriate exit codes
57 // InvalidArgumentError (e.g., invalid --type value) should exit with InvalidUsage (2)
58 if (err.code === 'commander.invalidArgument') {
59 process.exit(ExitCode.InvalidUsage)
60 }
61 // For other Commander errors, use the default exit code
62 process.exit(err.exitCode)
63 })
64 // Global options
65 .option('--no-color', 'Disable colored output (also respects NO_COLOR env var)')
66 .option('--debug', 'Show debug information for troubleshooting')
67 .option('-q, --quiet', 'Suppress non-essential output')
68 .hook('preAction', (thisCommand, _actionCommand) => {
69 const opts = thisCommand.opts<GlobalOptions>()
70
71 // Configure output based on global options
72 setOutputConfig({
73 color: opts.color && !shouldDisableColor(),
74 debug: opts.debug ?? false,
75 quiet: opts.quiet ?? false,
76 })
77
78 // Update chalk level if color is disabled
79 if (!getOutputConfig().color) {
80 chalk.level = 0
81 }
82 })
83 .addHelpText('after', () => {
84 const c = getChalk()
85 return `
86${c.bold('Examples:')}
87 ${c.dim('# Run the first .deepnote file in current directory')}
88 $ deepnote run
89
90 ${c.dim('# Inspect a specific .deepnote file')}
91 $ deepnote inspect my-project.deepnote
92
93 ${c.dim('# Run the first .deepnote file in a subdirectory')}
94 $ deepnote run notebooks/
95
96 ${c.dim('# Inspect with JSON output (for scripting)')}
97 $ deepnote inspect my-project.deepnote -o json
98
99 ${c.dim('# Display block contents')}

Callers 2

cli.test.tsFile · 0.90
runFunction · 0.85

Calls 6

setOutputConfigFunction · 0.90
shouldDisableColorFunction · 0.90
getOutputConfigFunction · 0.90
getChalkFunction · 0.90
getWelcomeTextFunction · 0.85
registerCommandsFunction · 0.85

Tested by

no test coverage detected