@@ -128,8 +128,11 @@ export const parse = (argv: string[]): Args => {
128128 // Options start with a dash and require a value if non-boolean.
129129 if ( ! ended && arg . startsWith ( "-" ) ) {
130130 let key : keyof Args | undefined
131+ let value : string | undefined
131132 if ( arg . startsWith ( "--" ) ) {
132- key = arg . replace ( / ^ - - / , "" ) as keyof Args
133+ const split = arg . replace ( / ^ - - / , "" ) . split ( "=" , 2 )
134+ key = split [ 0 ] as keyof Args
135+ value = split [ 1 ]
133136 } else {
134137 const short = arg . replace ( / ^ - / , "" )
135138 const pair = Object . entries ( options ) . find ( ( [ , v ] ) => v . short === short )
@@ -148,13 +151,17 @@ export const parse = (argv: string[]): Args => {
148151 continue
149152 }
150153
151- // A value is only valid if it doesn't look like an option.
152- let value = argv [ i + 1 ] && ! argv [ i + 1 ] . startsWith ( "-" ) ? argv [ ++ i ] : undefined
154+ // Might already have a value if it was the --long=value format.
155+ if ( typeof value === "undefined" ) {
156+ // A value is only valid if it doesn't look like an option.
157+ value = argv [ i + 1 ] && ! argv [ i + 1 ] . startsWith ( "-" ) ? argv [ ++ i ] : undefined
158+ }
159+
153160 if ( ! value && option . type === OptionalString ) {
154161 ; ( args [ key ] as OptionalString ) = new OptionalString ( value )
155162 continue
156163 } else if ( ! value ) {
157- throw new Error ( `${ arg } requires a value` )
164+ throw new Error ( `-- ${ key } requires a value` )
158165 }
159166
160167 if ( option . path ) {
@@ -174,15 +181,15 @@ export const parse = (argv: string[]): Args => {
174181 case "number" :
175182 ; ( args [ key ] as number ) = parseInt ( value , 10 )
176183 if ( isNaN ( args [ key ] as number ) ) {
177- throw new Error ( `${ arg } must be a number` )
184+ throw new Error ( `-- ${ key } must be a number` )
178185 }
179186 break
180187 case OptionalString :
181188 ; ( args [ key ] as OptionalString ) = new OptionalString ( value )
182189 break
183190 default : {
184191 if ( ! Object . values ( option . type ) . find ( ( v ) => v === value ) ) {
185- throw new Error ( `${ arg } valid values: [${ Object . values ( option . type ) . join ( ", " ) } ]` )
192+ throw new Error ( `-- ${ key } valid values: [${ Object . values ( option . type ) . join ( ", " ) } ]` )
186193 }
187194 ; ( args [ key ] as string ) = value
188195 break
0 commit comments