@@ -26,24 +26,31 @@ function unwrapType(type: unknown): unknown {
2626 return type ;
2727}
2828
29- /**
30- * Generate yargs-parser configuration from schema
31- */
32- export function generateYargsOptionsFromSchema ( {
33- schema,
34- configuration = {
29+ export const defaultParserOptions : Partial < YargsOptions > = {
30+ configuration : {
3531 'camel-case-expansion' : false ,
3632 'unknown-options-as-args' : true ,
3733 'parse-positional-numbers' : false ,
3834 'parse-numbers' : false ,
3935 'greedy-arrays' : false ,
4036 'short-option-groups' : false ,
4137 } ,
38+ } ;
39+
40+ export type ParserOptions = Partial < YargsOptions > ;
41+
42+ /**
43+ * Generate yargs-parser configuration from schema
44+ */
45+ export function generateYargsOptionsFromSchema ( {
46+ schema,
47+ parserOptions = defaultParserOptions ,
4248} : {
4349 schema : z . ZodObject ;
44- configuration ?: YargsOptions [ 'configuration' ] ;
50+ parserOptions ?: Partial < YargsOptions > ;
4551} ) : YargsOptions {
4652 const options = {
53+ ...parserOptions ,
4754 string : < string [ ] > [ ] ,
4855 boolean : < string [ ] > [ ] ,
4956 array : < string [ ] > [ ] ,
@@ -132,10 +139,7 @@ export function generateYargsOptionsFromSchema({
132139 }
133140 }
134141
135- return {
136- ...options ,
137- configuration,
138- } ;
142+ return options ;
139143}
140144
141145/**
@@ -157,11 +161,11 @@ export function getLocale(args: string[], env: any): string {
157161export function parseArgs < T > ( {
158162 args,
159163 schema,
160- parserConfiguration ,
164+ parserOptions ,
161165} : {
162166 args : string [ ] ;
163167 schema : z . ZodObject ;
164- parserConfiguration ?: YargsOptions [ 'configuration' ] ;
168+ parserOptions ?: YargsOptions ;
165169} ) : {
166170 /** Parsed options from the schema, including replaced deprecated arguments. */
167171 parsed : T & Omit < parser . Arguments , '_' > ;
@@ -172,7 +176,7 @@ export function parseArgs<T>({
172176} {
173177 const options = generateYargsOptionsFromSchema ( {
174178 schema,
175- configuration : parserConfiguration ,
179+ parserOptions ,
176180 } ) ;
177181
178182 const { _ : positional , ...parsedArgs } = parser ( args , options ) ;
@@ -222,24 +226,29 @@ type ParsedCliOptions = CliOptions & {
222226} ;
223227
224228/** Parses the arguments with special handling of mongosh CLI options fields. */
225- export function parseArgsWithCliOptions ( {
229+ export function parseArgsWithCliOptions <
230+ T extends CliOptions = ParsedCliOptions
231+ > ( {
226232 args,
227233 schema : schemaToExtend ,
234+ parserOptions,
228235} : {
229236 args : string [ ] ;
230237 /** Schema to extend the CLI options schema with. */
231238 schema ?: z . ZodObject ;
232- } ) : ReturnType < typeof parseArgs < CliOptions > > {
239+ parserOptions ?: Partial < YargsOptions > ;
240+ } ) : ReturnType < typeof parseArgs < T > > {
233241 const schema =
234242 schemaToExtend !== undefined
235243 ? z . object ( {
236244 ...CliOptionsSchema . shape ,
237245 ...schemaToExtend . shape ,
238246 } )
239247 : CliOptionsSchema ;
240- const { parsed, positional, deprecated } = parseArgs < ParsedCliOptions > ( {
248+ const { parsed, positional, deprecated } = parseArgs < T > ( {
241249 args,
242250 schema,
251+ parserOptions,
243252 } ) ;
244253
245254 const processed = processPositionalCliOptions ( {
0 commit comments