File tree 2 files changed +14
-1
lines changed
2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -173,7 +173,7 @@ export class Parser<
173
173
this . currentFlag = flag
174
174
let input = isLong || arg . length < 3 ? this . argv . shift ( ) : arg . slice ( arg [ 2 ] === '=' ? 3 : 2 )
175
175
176
- if ( flag . allowStdin === 'only' && input !== '-' && input !== undefined ) {
176
+ if ( flag . allowStdin === 'only' && input !== '-' && input !== undefined && ! this . findFlag ( input ) . name ) {
177
177
throw new CLIError (
178
178
`Flag --${ name } can only be read from stdin. The value must be "-" or not provided at all.` ,
179
179
)
Original file line number Diff line number Diff line change @@ -1956,4 +1956,17 @@ describe('allowStdin', () => {
1956
1956
}
1957
1957
}
1958
1958
} )
1959
+
1960
+ it ( 'should read stdin as input for flag when allowStdin is "only" and no value is given, and a second flag is used after' , async ( ) => {
1961
+ sandbox . stub ( parser , 'readStdin' ) . returns ( stdinPromise )
1962
+ const out = await parse ( [ '--myflag' , '--myflag2' ] , {
1963
+ flags : {
1964
+ myflag : Flags . string ( { allowStdin : 'only' } ) ,
1965
+ myflag2 : Flags . boolean ( ) ,
1966
+ } ,
1967
+ } )
1968
+
1969
+ expect ( out . flags . myflag ) . to . equals ( stdinValue )
1970
+ expect ( out . raw [ 0 ] . input ) . to . equal ( 'x' )
1971
+ } )
1959
1972
} )
You can’t perform that action at this time.
0 commit comments