@@ -1082,58 +1082,66 @@ test('help value for option must be a string', () => {
10821082 ) ;
10831083} ) ;
10841084
1085+ test ( 'when option has help text values but help arg value is not provided, then no help value appear' , ( ) => {
1086+ const args = [ '-f' , 'bar' ] ;
1087+ const options = { foo : { type : 'string' , short : 'f' , help : 'help text' } } ;
1088+ const expected = { values : { __proto__ : null , foo : 'bar' } , positionals : [ ] } ;
1089+ const result = parseArgs ( { args, options, allowPositionals : true } ) ;
1090+ assert . deepStrictEqual ( result , expected ) ;
1091+ } )
1092+
10851093test ( 'when option has short and long flags, then both appear in usage' , ( ) => {
10861094 const args = [ '-f' , 'bar' ] ;
10871095 const options = { foo : { type : 'string' , short : 'f' , help : 'help text' } } ;
10881096 const help = 'Description for some awesome stuff:' ;
10891097 const printUsage = help + '\n-f, --foo <arg> help text' ;
1090- const expected = { values : { __proto__ : null , foo : 'bar' } , positionals : [ ] , printUsage } ;
1098+ const expected = { values : { __proto__ : null , foo : 'bar' , help : printUsage } , positionals : [ ] } ;
10911099 const result = parseArgs ( { args, options, allowPositionals : true , help } ) ;
10921100 assert . deepStrictEqual ( result , expected ) ;
10931101} ) ;
10941102
1095- test ( 'when help arg with help value for short group option is added , then add help text ' , ( ) => {
1103+ test ( 'when options has short group flags , then both appear in usage ' , ( ) => {
10961104 const args = [ '-fm' , 'bar' ] ;
10971105 const options = { foo : { type : 'boolean' , short : 'f' , help : 'help text' } ,
10981106 moo : { type : 'string' , short : 'm' , help : 'help text' } } ;
10991107 const help = 'Description for some awesome stuff:' ;
11001108 const printUsage = help + '\n-f, --foo help text\n-m, --moo <arg> help text' ;
1101- const expected = { values : { __proto__ : null , foo : true , moo : 'bar' } , positionals : [ ] , printUsage } ;
1109+ const expected = { values : { help : printUsage , __proto__ : null , foo : true , moo : 'bar' } , positionals : [ ] } ;
11021110 const result = parseArgs ( { args, options, allowPositionals : true , help } ) ;
11031111 assert . deepStrictEqual ( result , expected ) ;
11041112} ) ;
11051113
1106- test ( 'when help arg with help value for short option and value is added , then add help text ' , ( ) => {
1114+ test ( 'when options has short flag with value, then both appear in usage ' , ( ) => {
11071115 const args = [ '-fFILE' ] ;
11081116 const options = { foo : { type : 'string' , short : 'f' , help : 'help text' } } ;
11091117 const help = 'Description for some awesome stuff:' ;
11101118 const printUsage = help + '\n-f, --foo <arg> help text' ;
1111- const expected = { values : { __proto__ : null , foo : 'FILE' } , positionals : [ ] , printUsage } ;
1119+ const expected = { values : { help : printUsage , __proto__ : null , foo : 'FILE' } , positionals : [ ] } ;
11121120 const result = parseArgs ( { args, options, allowPositionals : true , help } ) ;
11131121 assert . deepStrictEqual ( result , expected ) ;
11141122} ) ;
11151123
1116- test ( 'when help arg with help value for lone long option is added , then add help text ' , ( ) => {
1124+ test ( 'when options has long flag , then it appear in usage ' , ( ) => {
11171125 const args = [ '--foo' , 'bar' ] ;
11181126 const options = { foo : { type : 'string' , help : 'help text' } } ;
11191127 const help = 'Description for some awesome stuff:' ;
11201128 const printUsage = help + '\n--foo <arg> help text' ;
1121- const expected = { values : { __proto__ : null , foo : 'bar' } , positionals : [ ] , printUsage } ;
1129+ const expected = { values : { help : printUsage , __proto__ : null , foo : 'bar' } , positionals : [ ] } ;
11221130 const result = parseArgs ( { args, options, allowPositionals : true , help } ) ;
11231131 assert . deepStrictEqual ( result , expected ) ;
11241132} ) ;
11251133
1126- test ( 'when help arg with help value for lone long option and value is added , then add help text ' , ( ) => {
1134+ test ( 'when options has long flag with value, then both appear in usage ' , ( ) => {
11271135 const args = [ '--foo=bar' ] ;
11281136 const options = { foo : { type : 'string' , help : 'help text' } } ;
11291137 const help = 'Description for some awesome stuff:' ;
11301138 const printUsage = help + '\n--foo <arg> help text' ;
1131- const expected = { values : { __proto__ : null , foo : 'bar' } , positionals : [ ] , printUsage } ;
1139+ const expected = { values : { help : printUsage , __proto__ : null , foo : 'bar' } , positionals : [ ] } ;
11321140 const result = parseArgs ( { args, options, allowPositionals : true , help } ) ;
11331141 assert . deepStrictEqual ( result , expected ) ;
11341142} ) ;
11351143
1136- test ( 'when help arg with help values and without explicit help texts, then add help text ' , ( ) => {
1144+ test ( 'when options has help values with and without explicit texts, then all appear in usage ' , ( ) => {
11371145 const args = [
11381146 '-h' , '-a' , 'val1' ,
11391147 ] ;
@@ -1174,10 +1182,10 @@ test('when help arg with help values and without explicit help texts, then add h
11741182 '-L, --looooooooooooooongHelpText <arg>\n' +
11751183 ' Very long option help text for demonstration purposes' ;
11761184
1177- assert . strictEqual ( result . printUsage , printUsage ) ;
1185+ assert . strictEqual ( result . values . help , printUsage ) ;
11781186} ) ;
11791187
1180- test ( 'when help arg but no help text is available , then add help text ' , ( ) => {
1188+ test ( 'when general help text and options with no help values , then all appear in usage ' , ( ) => {
11811189 const args = [ '-a' , 'val1' , '--help' ] ;
11821190 const help = 'Description for some awesome stuff:' ;
11831191 const options = { alpha : { type : 'string' , short : 'a' } , help : { type : 'boolean' } } ;
@@ -1188,5 +1196,5 @@ test('when help arg but no help text is available, then add help text', () => {
11881196
11891197 const result = parseArgs ( { args, options, help } ) ;
11901198
1191- assert . strictEqual ( result . printUsage , printUsage ) ;
1199+ assert . strictEqual ( result . values . help , printUsage ) ;
11921200} ) ;
0 commit comments