@@ -117,6 +117,7 @@ export class Massarg<Options extends OptionsBase = OptionsBase> {
117117 if ( option ) {
118118 // detect boolean values
119119 option . boolean ??= option . parse === Boolean || [ true , false ] . includes ( option . defaultValue )
120+ option . array ??= Array . isArray ( option . defaultValue )
120121
121122 let tempValue : any
122123 const hasNextToken = args . length > i + 1
@@ -180,8 +181,36 @@ export class Massarg<Options extends OptionsBase = OptionsBase> {
180181
181182 private _addOptionToData ( option : OptionDef < Options , any > , value : any ) {
182183 const _d : Record < string , any > = this . data
183- _d [ camelCase ( option . name ) ] = value
184- option . aliases ?. forEach ( ( a ) => ( _d [ a ] = value ) )
184+ const set = ( value : any ) => {
185+ _d [ option . name ] = value
186+ _d [ camelCase ( option . name ) ] = value
187+ option . aliases ?. forEach ( ( a ) => ( _d [ a ] = value ) )
188+ }
189+ const push = ( value : any ) = > {
190+ const ccSame = camelCase ( option . name ) === option . name
191+ _d [ option . name ] ??= [ ]
192+ _d [ camelCase ( option . name ) ] ??= [ ]
193+ option . aliases ?. forEach ( ( a ) => ( _d [ a ] ??= [ ] ) )
194+
195+ _d [ option . name ] . push ( value )
196+ if ( ! ccSame ) {
197+ _d [ camelCase ( option . name ) ] . push ( value )
198+ }
199+ option . aliases ?. forEach ( ( a ) => _d [ a ] . push ( value ) )
200+ }
201+ if ( ! option . array ) {
202+ // single value
203+ set ( value )
204+ } else {
205+ // multiple values
206+ if ( Array . isArray ( value ) && value . length ) {
207+ for ( const el of value ) {
208+ push ( el )
209+ }
210+ } else if ( ! Array . isArray ( value ) ) {
211+ push ( value )
212+ }
213+ }
185214 }
186215
187216 private _getWrappedLines ( list : Array < { name : string ; description ? : string } > ) : string [ ] {
0 commit comments