(argv: string[], config: PrismaConfigInternal, baseDir: string)
| 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. |
| 105 | See \`${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. |
| 110 | See \`${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 }) |
nothing calls this directly
no test coverage detected