MCPcopy
hub / github.com/prisma/prisma / CLI

Class CLI

packages/cli/src/CLI.ts:15–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13 * CLI command
14 */
15export class CLI implements Command {
16 static new(
17 cmds: Commands,
18 ensureBinaries: string[],
19 download: (options: DownloadOptions) => Promise<BinaryPaths>,
20 ): CLI {
21 return new CLI(cmds, ensureBinaries, download)
22 }
23
24 private constructor(
25 private readonly cmds: Commands,
26 private readonly ensureBinaries: string[],
27 private readonly download: (options: DownloadOptions) => Promise<BinaryPaths>,
28 ) {}
29
30 async parse(argv: string[], config: PrismaConfigInternal, baseDir: string = process.cwd()): Promise<string | Error> {
31 const args = arg(argv, {
32 '--help': Boolean,
33 '-h': '--help',
34 '--version': Boolean,
35 '-v': '--version',
36 '--config': String,
37 '--json': Boolean, // for -v
38 '--experimental': Boolean,
39 '--preview-feature': Boolean,
40 '--early-access': Boolean,
41 '--telemetry-information': String,
42 })
43
44 if (isError(args)) {
45 return this.help(args.message)
46 }
47
48 // display help for help flag or no subcommand
49 if (!args['--version'] && (args._.length === 0 || args['--help'])) {
50 return this.help()
51 }
52
53 if (args['--version']) {
54 await ensureNeededBinariesExist({
55 download: this.download,
56 })
57 return Version.new().parse(argv, config, baseDir)
58 }
59
60 // check if we have that subcommand
61 const cmdName = args._[0]
62 // Throw if "lift"
63 if (cmdName === 'lift') {
64 throw new Error(`${red('prisma lift')} has been renamed to ${green('prisma migrate')}`)
65 }
66
67 const cmd = this.cmds[cmdName]
68 if (cmd) {
69 // Only track if the command actually exists
70 const checkResultPromise = runCheckpointClientCheck({ schemaPathFromConfig: config.schema, baseDir }).catch(
71 () => {
72 /* noop */

Callers

nothing calls this directly

Calls 3

linkFunction · 0.90
drawBoxFunction · 0.90
formatFunction · 0.90

Tested by

no test coverage detected