File tree Expand file tree Collapse file tree 2 files changed +26
-5
lines changed
Expand file tree Collapse file tree 2 files changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -6,22 +6,43 @@ const argv = yargs
66 describe : "Specify the output directory" ,
77 type : "string" ,
88 demandOption : false ,
9+ default : "dist" ,
910 } )
1011 . option ( "framework" , {
1112 alias : "f" ,
1213 describe : "Specify the target framework" ,
1314 type : "string" ,
1415 demandOption : false ,
16+ default : null ,
1517 } )
1618 . option ( "schemas" , {
1719 alias : "s" ,
1820 describe : "Specify the path for predefined zod schemas" ,
1921 type : "string" ,
2022 demandOption : false ,
23+ default : null ,
2124 } )
2225 . argv ;
2326
24- export default async function getArgument ( name : string ) {
27+ type RemoveKeys < T , K extends keyof T > = {
28+ [ P in keyof T as P extends K ? never : P ] : T [ P ] ;
29+ } ;
30+
31+ type RemoveIndex < T > = {
32+ [ K in keyof T as
33+ string extends K
34+ ? never
35+ : number extends K
36+ ? never
37+ : symbol extends K
38+ ? never
39+ : K
40+ ] : T [ K ] ;
41+ } ;
42+
43+ type Arguments = RemoveKeys < RemoveIndex < Awaited < typeof argv > > , "_" | "$0" > ;
44+
45+ export default async function getArgument < N extends keyof Arguments > ( name : N ) {
2546 const a = argv instanceof Promise ? await argv : argv ;
26- return a [ name ] as string | undefined ;
47+ return a [ name ] as Arguments [ N ] ;
2748}
Original file line number Diff line number Diff line change @@ -8,12 +8,12 @@ import createFile from "./core/file";
88import findPredefinedSchemas from "./core/schemas" ;
99
1010( async ( ) => {
11- const outputFolder = await getArgument ( "output" ) ?? "dist" ;
11+ const outputFolder = await getArgument ( "output" ) ;
1212 const outputDir = path . resolve ( process . cwd ( ) , outputFolder ) ;
1313
14- const framework = await getArgument ( "framework" ) ?? null ;
14+ const framework = await getArgument ( "framework" ) ;
1515
16- const schemaPaths = await getArgument ( "schemas" ) ?? null ;
16+ const schemaPaths = await getArgument ( "schemas" ) ;
1717 const schemas = await findPredefinedSchemas ( schemaPaths ) ;
1818
1919 const spec = await generateOpenApiSpec ( schemas ) ;
You can’t perform that action at this time.
0 commit comments