| 45 | private constructor(private readonly cmds: Commands) {} |
| 46 | |
| 47 | public async parse(argv: string[], config: PrismaConfigInternal, baseDir: string): Promise<string | Error> { |
| 48 | const args = arg(argv, { |
| 49 | '--help': Boolean, |
| 50 | '-h': '--help', |
| 51 | '--config': String, |
| 52 | '--preview-feature': Boolean, |
| 53 | '--telemetry-information': String, |
| 54 | }) |
| 55 | |
| 56 | if (isError(args)) { |
| 57 | return this.help(args.message) |
| 58 | } |
| 59 | |
| 60 | // display help for help flag or no subcommand |
| 61 | if (args._.length === 0 || args['--help']) { |
| 62 | return this.help() |
| 63 | } |
| 64 | |
| 65 | // check if we have that subcommand |
| 66 | const cmd = this.cmds[args._[0]] |
| 67 | if (cmd) { |
| 68 | const argsForCmd = args['--preview-feature'] ? [...args._.slice(1), `--preview-feature`] : args._.slice(1) |
| 69 | return cmd.parse(argsForCmd, config, baseDir) |
| 70 | } |
| 71 | |
| 72 | return unknownCommand(DbCommand.help, args._[0]) |
| 73 | } |
| 74 | |
| 75 | public help(error?: string): string | HelpError { |
| 76 | if (error) { |