MCPcopy
hub / github.com/prisma/prisma / parse

Method parse

packages/cli/src/bootstrap/Bootstrap.ts:88–139  ·  view source on GitHub ↗
(argv: string[], config: PrismaConfigInternal, baseDir: string)

Source from the content-addressed store, hash-verified

86`)
87
88 public async parse(argv: string[], config: PrismaConfigInternal, baseDir: string): Promise<string | Error> {
89 const args = arg(argv, {
90 '--api-key': String,
91 '--database': String,
92 '--template': String,
93 '--force': Boolean,
94 '--help': Boolean,
95 '-h': '--help',
96 '--telemetry-information': String,
97 })
98
99 if (isError(args)) {
100 return this.help(args.message)
101 }
102
103 if (args['--help']) {
104 return this.help()
105 }
106
107 const apiKey = args['--api-key']
108 const databaseId = args['--database']
109 const templateName = args['--template']
110 const force = args['--force'] ?? false
111
112 if (apiKey && !databaseId) {
113 return new HelpError(
114 `\n${bold(red('!'))} Missing ${bold('--database')} flag.\n\nWhen using ${bold('--api-key')}, you must also provide ${bold('--database')}.\n${Bootstrap.help}`,
115 )
116 }
117
118 if (databaseId && !databaseId.startsWith('db_')) {
119 return new HelpError(
120 `\n${bold(red('!'))} Invalid database ID "${databaseId}" — expected format: ${bold('db_<id>')}\n${Bootstrap.help}`,
121 )
122 }
123
124 if (templateName && !isValidTemplateName(templateName)) {
125 return new HelpError(
126 `\n${bold(red('!'))} Unknown template "${templateName}". Available templates: nextjs, express, hono, fastify, nuxt, sveltekit, remix, react-router-7, astro, nest\n${Bootstrap.help}`,
127 )
128 }
129
130 try {
131 return await this.run(apiKey, databaseId, templateName, force, config, baseDir)
132 } catch (err) {
133 if (err instanceof LinkApiError) {
134 return new HelpError(`\n${bold(red('!'))} ${sanitizeErrorMessage(err.message)}`)
135 }
136 const message = err instanceof Error ? err.message : String(err)
137 return new HelpError(`\n${bold(red('!'))} ${sanitizeErrorMessage(message)}`)
138 }
139 }
140
141 private async run(
142 apiKey: string | undefined,

Callers

nothing calls this directly

Calls 6

helpMethod · 0.95
runMethod · 0.95
argFunction · 0.90
isErrorFunction · 0.90
isValidTemplateNameFunction · 0.90
sanitizeErrorMessageFunction · 0.90

Tested by

no test coverage detected