@@ -1401,17 +1401,33 @@ class Command extends EventEmitter {
1401
1401
1402
1402
optionHelp ( ) {
1403
1403
const width = this . padWidth ( ) ;
1404
-
1405
1404
const columns = process . stdout . columns || 80 ;
1406
1405
const descriptionWidth = columns - width - 4 ;
1406
+ function padOptionDetails ( flags , description ) {
1407
+ return pad ( flags , width ) + ' ' + optionalWrap ( description , descriptionWidth , width + 2 ) ;
1408
+ } ;
1407
1409
1408
- // Append the help information
1409
- return this . options . map ( ( option ) => {
1410
+ // Explicit options (including version)
1411
+ const help = this . options . map ( ( option ) => {
1410
1412
const fullDesc = option . description +
1411
1413
( ( ! option . negate && option . defaultValue !== undefined ) ? ' (default: ' + JSON . stringify ( option . defaultValue ) + ')' : '' ) ;
1412
- return pad ( option . flags , width ) + ' ' + optionalWrap ( fullDesc , descriptionWidth , width + 2 ) ;
1413
- } ) . concat ( [ pad ( this . _helpFlags , width ) + ' ' + optionalWrap ( this . _helpDescription , descriptionWidth , width + 2 ) ] )
1414
- . join ( '\n' ) ;
1414
+ return padOptionDetails ( option . flags , fullDesc ) ;
1415
+ } ) ;
1416
+
1417
+ // Implicit help
1418
+ const showShortHelpFlag = this . _helpShortFlag && ! this . _findOption ( this . _helpShortFlag ) ;
1419
+ const showLongHelpFlag = ! this . _findOption ( this . _helpLongFlag ) ;
1420
+ if ( showShortHelpFlag || showLongHelpFlag ) {
1421
+ let helpFlags = this . _helpFlags ;
1422
+ if ( ! showShortHelpFlag ) {
1423
+ helpFlags = this . _helpLongFlag ;
1424
+ } else if ( ! showLongHelpFlag ) {
1425
+ helpFlags = this . _helpShortFlag ;
1426
+ }
1427
+ help . push ( padOptionDetails ( helpFlags , this . _helpDescription ) ) ;
1428
+ }
1429
+
1430
+ return help . join ( '\n' ) ;
1415
1431
} ;
1416
1432
1417
1433
/**
0 commit comments