@@ -128,8 +128,11 @@ export const parse = (argv: string[]): Args => {
128
128
// Options start with a dash and require a value if non-boolean.
129
129
if ( ! ended && arg . startsWith ( "-" ) ) {
130
130
let key : keyof Args | undefined
131
+ let value : string | undefined
131
132
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 ]
133
136
} else {
134
137
const short = arg . replace ( / ^ - / , "" )
135
138
const pair = Object . entries ( options ) . find ( ( [ , v ] ) => v . short === short )
@@ -148,13 +151,17 @@ export const parse = (argv: string[]): Args => {
148
151
continue
149
152
}
150
153
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
+
153
160
if ( ! value && option . type === OptionalString ) {
154
161
; ( args [ key ] as OptionalString ) = new OptionalString ( value )
155
162
continue
156
163
} else if ( ! value ) {
157
- throw new Error ( `${ arg } requires a value` )
164
+ throw new Error ( `-- ${ key } requires a value` )
158
165
}
159
166
160
167
if ( option . path ) {
@@ -174,15 +181,15 @@ export const parse = (argv: string[]): Args => {
174
181
case "number" :
175
182
; ( args [ key ] as number ) = parseInt ( value , 10 )
176
183
if ( isNaN ( args [ key ] as number ) ) {
177
- throw new Error ( `${ arg } must be a number` )
184
+ throw new Error ( `-- ${ key } must be a number` )
178
185
}
179
186
break
180
187
case OptionalString :
181
188
; ( args [ key ] as OptionalString ) = new OptionalString ( value )
182
189
break
183
190
default : {
184
191
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 ( ", " ) } ]` )
186
193
}
187
194
; ( args [ key ] as string ) = value
188
195
break
0 commit comments