| 64 | private constructor(private readonly cmds: Commands) {} |
| 65 | |
| 66 | public async parse(argv: string[], config: PrismaConfigInternal, baseDir: string): Promise<string | Error> { |
| 67 | const args = arg(argv, { |
| 68 | '--help': Boolean, |
| 69 | '-h': '--help', |
| 70 | '--config': String, |
| 71 | '--preview-feature': Boolean, |
| 72 | '--telemetry-information': String, |
| 73 | }) |
| 74 | |
| 75 | if (isError(args)) { |
| 76 | return this.help(args.message) |
| 77 | } |
| 78 | |
| 79 | // display help for help flag or no subcommand |
| 80 | if (args._.length === 0 || args['--help']) { |
| 81 | return this.help() |
| 82 | } |
| 83 | |
| 84 | const commandName = args._[0] |
| 85 | |
| 86 | // check if we have that subcommand |
| 87 | const cmd = this.cmds[commandName] |
| 88 | if (cmd) { |
| 89 | let argsForCmd: string[] |
| 90 | if (commandName === 'diff') { |
| 91 | argsForCmd = args['--preview-feature'] ? [...args._.slice(1), `--preview-feature`] : args._.slice(1) |
| 92 | } else { |
| 93 | // Filter our --preview-feature flag for other migrate commands that do not consider it valid |
| 94 | const filteredArgs = args._.filter((item) => item !== '--preview-feature') |
| 95 | argsForCmd = filteredArgs.slice(1) |
| 96 | } |
| 97 | |
| 98 | return cmd.parse(argsForCmd, config, baseDir) |
| 99 | } |
| 100 | |
| 101 | return unknownCommand(MigrateCommand.help, commandName) |
| 102 | } |
| 103 | |
| 104 | public help(error?: string): string | HelpError { |
| 105 | if (error) { |