@@ -42,14 +42,14 @@ test.set('--option <no value>', async function () {
4242 a . deepEqual ( cla . argv , [ 'one' , 'two' , '--two' , 'three' ] )
4343} )
4444
45- test . set ( 'single --option flag' , async function ( ) {
45+ test . set ( 'single --option flag, value set ' , async function ( ) {
4646 const argv = [ 'one' , 'two' , '--one' , '--two' ]
4747 const optionDefinitions = [
4848 {
4949 name : 'one' ,
5050 extractor : 'single' ,
5151 single : '--one' ,
52- output : extraction => true
52+ output : extraction => extraction . length === 1 ? true : undefined
5353 }
5454 ]
5555 const cla = new CommandLineArgs ( argv )
@@ -58,6 +58,38 @@ test.set('single --option flag', async function () {
5858 a . deepEqual ( cla . argv , [ 'one' , 'two' , '--two' ] )
5959} )
6060
61+ test . set ( 'single --option flag, value set not, output returns false' , async function ( ) {
62+ const argv = [ 'one' , 'two' , '--two' ]
63+ const optionDefinitions = [
64+ {
65+ name : 'one' ,
66+ extractor : 'single' ,
67+ single : '--one' ,
68+ output : extraction => extraction . length === 1
69+ }
70+ ]
71+ const cla = new CommandLineArgs ( argv )
72+ const result = await cla . parse ( optionDefinitions )
73+ a . deepEqual ( result , { one : false } )
74+ a . deepEqual ( cla . argv , [ 'one' , 'two' , '--two' ] )
75+ } )
76+
77+ test . set ( 'single --option flag, not set. Returning undefined omits option from result.' , async function ( ) {
78+ const argv = [ 'one' , 'two' , '--two' ]
79+ const optionDefinitions = [
80+ {
81+ name : 'one' ,
82+ extractor : 'single' ,
83+ single : '--one' ,
84+ output : extraction => extraction . length === 1 ? true : undefined
85+ }
86+ ]
87+ const cla = new CommandLineArgs ( argv )
88+ const result = await cla . parse ( optionDefinitions )
89+ a . deepEqual ( result , { } )
90+ a . deepEqual ( cla . argv , [ 'one' , 'two' , '--two' ] )
91+ } )
92+
6193test . set ( 'single regex' , async function ( ) {
6294 const argv = [ 'one' , 'two' , '--one' , '--two' ]
6395 const optionDefinitions = [
0 commit comments