require ( "source-map-support" ) . install ( ) ; import { makeBooleanFlag , makeCommand , reduceFlag , Flag , FlagOption , ParseResult } from "../main" ; type StringArrayFlag < N extends string > = Flag < string [ ] , N > ; function makeStringArrayFlag2 < N extends string > ( name , option ) { return ( args ) => { const flagName = `--${ name }` ; const idxes = args . map ( ( a , i ) => { if ( a === flagName ) { return i ; } } ) . filter ( i => i ) ; const values = idxes . map ( i => args [ i + 1 ] ) ; const position = idxes . map ( i => [ i , i + 1 ] ) . flat ( ) ; return < ParseResult < string [ ] , N > > { [ name ] : { value : values , position , option } } ; } ; } const booleanFlag = makeBooleanFlag ( "opts1" , { usage : "boolean example" } ) ; const stringArrayFlag2 = makeStringArrayFlag2 ( "arr2" , { usage : "custom-flag2 example" } ) ; const flags = reduceFlag ( booleanFlag , stringArrayFlag2 ) ; const command = makeCommand ( { name : "example" , description : "catacli is typescript-friendly commander tool" , version : "0.0.1" , usage : "simple [OPTIONS] arg1" , flag : flags , handler : ( _ , opts ) => { console . log ( "opts1: " , opts . opts1 . value ) ; console . log ( "flag arr: " , opts . arr2 . value ) ; } } ) ; command ( process . argv . splice ( 2 ) ) ;