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

Method parse

packages/migrate/src/commands/DbExecute.ts:76–156  ·  view source on GitHub ↗
(argv: string[], config: PrismaConfigInternal, baseDir: string)

Source from the content-addressed store, hash-verified

74`)
75
76 public async parse(argv: string[], config: PrismaConfigInternal, baseDir: string): Promise<string | Error> {
77 const args = arg(
78 argv,
79 {
80 '--help': Boolean,
81 '-h': '--help',
82 '--config': String,
83 '--stdin': Boolean,
84 '--file': String,
85 '--telemetry-information': String,
86 },
87 false,
88 )
89
90 if (isError(args)) {
91 return this.help(args.message)
92 }
93
94 if (args['--help']) {
95 return this.help()
96 }
97
98 const cmd = 'db execute'
99 const validatedConfig = validatePrismaConfigWithDatasource({ config, cmd })
100
101 // One of --stdin or --file is required
102 if (args['--stdin'] && args['--file']) {
103 throw new Error(
104 `--stdin and --file cannot be used at the same time. Only 1 must be provided.
105See \`${green(getCommandWithExecutor('prisma db execute -h'))}\``,
106 )
107 } else if (!args['--stdin'] && !args['--file']) {
108 throw new Error(
109 `Either --stdin or --file must be provided.
110See \`${green(getCommandWithExecutor('prisma db execute -h'))}\``,
111 )
112 }
113
114 let script = ''
115 // Read file
116 if (args['--file']) {
117 try {
118 script = fs.readFileSync(path.resolve(args['--file']), 'utf-8')
119 } catch (e) {
120 if (e.code === 'ENOENT') {
121 throw new Error(`Provided --file at ${args['--file']} doesn't exist.`)
122 } else {
123 console.error(`An error occurred while reading the provided --file at ${args['--file']}`)
124 throw e
125 }
126 }
127 }
128 // Read stdin
129 if (args['--stdin']) {
130 script = await streamConsumer.text(process.stdin)
131 }
132
133 checkUnsupportedDataProxy({ cmd, validatedConfig })

Callers

nothing calls this directly

Calls 10

helpMethod · 0.95
argFunction · 0.90
isErrorFunction · 0.90
getCommandWithExecutorFunction · 0.90
errorMethod · 0.80
dbExecuteMethod · 0.65
stopMethod · 0.65
setupMethod · 0.45

Tested by

no test coverage detected