@@ -1075,7 +1075,7 @@ test('help value for option must be a string', () => {
10751075test ( 'when help value for lone short option is added, then add help text' , ( ) => {
10761076 const args = [ '-f' , 'bar' ] ;
10771077 const options = { foo : { type : 'string' , short : 'f' , help : 'help text' } } ;
1078- const printUsage = [ '-f, --foo <arg> help text' ] ;
1078+ const printUsage = '-f, --foo <arg> help text' ;
10791079 const expected = { values : { __proto__ : null , foo : 'bar' } , positionals : [ ] , printUsage } ;
10801080 const result = parseArgs ( { args, options, allowPositionals : true } ) ;
10811081 assert . deepStrictEqual ( result , expected ) ;
@@ -1085,8 +1085,7 @@ test('when help value for short group option is added, then add help text', () =
10851085 const args = [ '-fm' , 'bar' ] ;
10861086 const options = { foo : { type : 'boolean' , short : 'f' , help : 'help text' } ,
10871087 moo : { type : 'string' , short : 'm' , help : 'help text' } } ;
1088- const printUsage = [ '-f, --foo help text' ,
1089- '-m, --moo <arg> help text' ] ;
1088+ const printUsage = '-f, --foo help text\n-m, --moo <arg> help text' ;
10901089 const expected = { values : { __proto__ : null , foo : true , moo : 'bar' } , positionals : [ ] , printUsage } ;
10911090 const result = parseArgs ( { args, options, allowPositionals : true } ) ;
10921091 assert . deepStrictEqual ( result , expected ) ;
@@ -1095,7 +1094,7 @@ test('when help value for short group option is added, then add help text', () =
10951094test ( 'when help value for short option and value is added, then add help text' , ( ) => {
10961095 const args = [ '-fFILE' ] ;
10971096 const options = { foo : { type : 'string' , short : 'f' , help : 'help text' } } ;
1098- const printUsage = [ '-f, --foo <arg> help text' ] ;
1097+ const printUsage = '-f, --foo <arg> help text' ;
10991098 const expected = { values : { __proto__ : null , foo : 'FILE' } , positionals : [ ] , printUsage } ;
11001099 const result = parseArgs ( { args, options, allowPositionals : true } ) ;
11011100 assert . deepStrictEqual ( result , expected ) ;
@@ -1104,7 +1103,7 @@ test('when help value for short option and value is added, then add help text',
11041103test ( 'when help value for lone long option is added, then add help text' , ( ) => {
11051104 const args = [ '--foo' , 'bar' ] ;
11061105 const options = { foo : { type : 'string' , help : 'help text' } } ;
1107- const printUsage = [ '--foo <arg> help text' ] ;
1106+ const printUsage = '--foo <arg> help text' ;
11081107 const expected = { values : { __proto__ : null , foo : 'bar' } , positionals : [ ] , printUsage } ;
11091108 const result = parseArgs ( { args, options, allowPositionals : true } ) ;
11101109 assert . deepStrictEqual ( result , expected ) ;
@@ -1113,7 +1112,7 @@ test('when help value for lone long option is added, then add help text', () =>
11131112test ( 'when help value for lone long option and value is added, then add help text' , ( ) => {
11141113 const args = [ '--foo=bar' ] ;
11151114 const options = { foo : { type : 'string' , help : 'help text' } } ;
1116- const printUsage = [ '--foo <arg> help text' ] ;
1115+ const printUsage = '--foo <arg> help text' ;
11171116 const expected = { values : { __proto__ : null , foo : 'bar' } , positionals : [ ] , printUsage } ;
11181117 const result = parseArgs ( { args, options, allowPositionals : true } ) ;
11191118 assert . deepStrictEqual ( result , expected ) ;
@@ -1133,7 +1132,7 @@ test('when help value is added, then add initial help text', () => {
11331132 const args = [ '-f' , 'bar' ] ;
11341133 const options = { foo : { type : 'string' , short : 'f' , help : 'help text' } } ;
11351134 const help = 'Description for some awesome stuff:' ;
1136- const printUsage = [ help , ' -f, --foo <arg> help text'] ;
1135+ const printUsage = help + '\n -f, --foo <arg> help text';
11371136 const expected = { values : { __proto__ : null , foo : 'bar' } , positionals : [ ] , printUsage } ;
11381137 const result = parseArgs ( { args, options, help } ) ;
11391138 assert . deepStrictEqual ( result , expected ) ;
@@ -1178,19 +1177,20 @@ test('when enableHelpPrinting config is true, print all help text and exit', ()
11781177
11791178 try {
11801179 const args = [
1181- '-a' , 'val1' , '--beta' , '-c' , 'val3' , '--delta' , 'val4' , '-e' ,
1182- '--foxtrot' , 'val6' , '--golf' , '-h ' , 'val8' , '--india' , 'val9' , '-j' ,
1180+ '-h' , '- a', 'val1' , '--beta' , '-c' , 'val3' , '--delta' , 'val4' , '-e' ,
1181+ '--foxtrot' , 'val6' , '--golf' , '--hotel ' , 'val8' , '--india' , 'val9' , '-j' ,
11831182 ] ;
11841183 const options = {
1184+ help : { type : 'boolean' , short : 'h' , help : 'Prints command line options' } ,
11851185 alpha : { type : 'string' , short : 'a' , help : 'Alpha option help' } ,
11861186 beta : { type : 'boolean' , short : 'b' , help : 'Beta option help' } ,
1187- charlie : { type : 'string' , short : 'c' , help : 'Charlie option help' } ,
1187+ charlie : { type : 'string' , short : 'c' } ,
11881188 delta : { type : 'string' , help : 'Delta option help' } ,
11891189 echo : { type : 'boolean' , short : 'e' , help : 'Echo option help' } ,
11901190 foxtrot : { type : 'string' , help : 'Foxtrot option help' } ,
11911191 golf : { type : 'boolean' , help : 'Golf option help' } ,
1192- hotel : { type : 'string' , short : 'h' , help : 'Hotel option help' } ,
1193- india : { type : 'string' , help : 'India option help' } ,
1192+ hotel : { type : 'string' , help : 'Hotel option help' } ,
1193+ india : { type : 'string' } ,
11941194 juliet : { type : 'boolean' , short : 'j' , help : 'Juliet option help' } ,
11951195 looooooooooooooongHelpText : {
11961196 type : 'string' ,
@@ -1207,15 +1207,14 @@ test('when enableHelpPrinting config is true, print all help text and exit', ()
12071207
12081208 const expectedOutput =
12091209 'Description for some awesome stuff:\n' +
1210+ '-h, --help Prints command line options\n' +
12101211 '-a, --alpha <arg> Alpha option help\n' +
12111212 '-b, --beta Beta option help\n' +
1212- '-c, --charlie <arg> Charlie option help\n' +
12131213 '--delta <arg> Delta option help\n' +
12141214 '-e, --echo Echo option help\n' +
12151215 '--foxtrot <arg> Foxtrot option help\n' +
12161216 '--golf Golf option help\n' +
1217- '-h, --hotel <arg> Hotel option help\n' +
1218- '--india <arg> India option help\n' +
1217+ '--hotel <arg> Hotel option help\n' +
12191218 '-j, --juliet Juliet option help\n' +
12201219 '-L, --looooooooooooooongHelpText <arg>\n' +
12211220 ' Very long option help text for demonstration purposes\n' ;
@@ -1228,8 +1227,8 @@ test('when enableHelpPrinting config is true, but no help text is available', ()
12281227 const { getOutput, getExitCode, restore } = setupConsoleAndExit ( ) ;
12291228
12301229 try {
1231- const args = [ '-a' , 'val1' ] ;
1232- const options = { alpha : { type : 'string' , short : 'a' } } ;
1230+ const args = [ '-a' , 'val1' , '--help' ] ;
1231+ const options = { alpha : { type : 'string' , short : 'a' } , help : { type : 'boolean' } } ;
12331232
12341233 parseArgs ( { args, options, enableHelpPrinting : true } ) ;
12351234 } finally {
0 commit comments