Skip to content

Commit aae3431

Browse files
committed
fix flag defaults
1 parent fd7d544 commit aae3431

File tree

1 file changed

+11
-13
lines changed
  • packages/core/src/scripts

1 file changed

+11
-13
lines changed

packages/core/src/scripts/cli.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,23 @@ export type Flags = {
1717
};
1818

1919
function defaultFlags(flags: Partial<Flags>, defaults: Partial<Flags>) {
20+
flags = { ...defaults, ...flags };
21+
2022
for (const [key, value] of Object.entries(flags)) {
21-
if (!(key in defaults)) throw new Error(`Option '${key}' is unsupported for this command`);
23+
if (value !== undefined && !(key in defaults)) {
24+
throw new Error(`Option '${key}' is unsupported for this command`);
25+
}
2226

27+
const defaultValue = defaults[key as keyof Flags];
2328
// should we default the flag?
2429
if (value === undefined) {
25-
flags[key as keyof Flags] = defaults[key as keyof Flags];
30+
flags[key as keyof Flags] = defaultValue;
2631
}
27-
}
2832

33+
if (typeof value !== typeof defaultValue) {
34+
throw new Error(`Option '${key}' should be of type ${typeof defaultValue}`);
35+
}
36+
}
2937
return flags as Flags;
3038
}
3139

@@ -65,16 +73,6 @@ export async function cli(cwd: string, argv: string[]) {
6573
trigger prisma to run migrations as part of startup
6674
`,
6775
{
68-
allowUnknownFlags: false,
69-
flags: {
70-
dbPush: { type: 'boolean' },
71-
frozen: { type: 'boolean' },
72-
prisma: { type: 'boolean' },
73-
server: { type: 'boolean' },
74-
ui: { type: 'boolean' },
75-
withMigrations: { type: 'boolean' },
76-
fix: { type: 'boolean' }, // TODO: remove - deprecated
77-
},
7876
argv,
7977
}
8078
);

0 commit comments

Comments
 (0)