1
+ const colors = require ( 'ansi-colors' ) ;
2
+
1
3
const MAX_LINE_WIDTH = process . stdout . columns || 200 ;
2
4
const MIN_OFFSET = 20 ;
3
5
const reAstral = / [ \uD800 - \uDBFF ] [ \uDC00 - \uDFFF ] / g;
4
6
const ansiRegex = / \x1B \[ ( [ 0 - 9 ] { 1 , 3 } ( ; [ 0 - 9 ] { 1 , 3 } ) * ) ? [ m | K ] / g;
5
7
const byName = ( a , b ) => a . name > b . name || - ( a . name < b . name ) ;
6
- let chalk ;
7
-
8
- function initChalk ( ) {
9
- if ( ! chalk ) {
10
- const ChalkInstance = require ( 'chalk' ) . Instance ;
11
-
12
- chalk = new ChalkInstance ( {
13
- level : Number ( process . stdout . isTTY )
14
- } ) ;
15
- }
16
-
17
- return chalk ;
18
- }
19
8
20
9
function stringLength ( str ) {
21
10
return str
@@ -82,7 +71,7 @@ function commandsHelp(command) {
82
71
83
72
const lines = command . getCommands ( ) . sort ( byName ) . map ( ( { name, meta, params } ) => ( {
84
73
description : meta . description ,
85
- name : chalk . green ( name ) + args ( params , chalk . gray )
74
+ name : colors . green ( name ) + args ( params , colors . gray )
86
75
} ) ) ;
87
76
88
77
return [
@@ -104,8 +93,8 @@ function optionsHelp(command) {
104
93
const lines = options . map ( ( { short, long, params, description } ) => ( {
105
94
description,
106
95
name : [
107
- short ? chalk . yellow ( short ) + ', ' : shortPlaceholder ,
108
- chalk . yellow ( long ) ,
96
+ short ? colors . yellow ( short ) + ', ' : shortPlaceholder ,
97
+ colors . yellow ( long ) ,
109
98
args ( params )
110
99
] . join ( '' )
111
100
} ) ) ;
@@ -127,19 +116,17 @@ function optionsHelp(command) {
127
116
* @api private
128
117
*/
129
118
module . exports = function getCommandHelp ( command , commandPath ) {
130
- initChalk ( ) ;
131
-
132
119
commandPath = Array . isArray ( commandPath ) && commandPath . length
133
120
? commandPath . concat ( command . name ) . join ( ' ' )
134
121
: command . name ;
135
122
136
123
return [
137
124
( command . meta . description ? command . meta . description + '\n\n' : '' ) +
138
125
'Usage:\n\n' +
139
- ' ' + chalk . cyan ( commandPath ) +
140
- args ( command . params , chalk . magenta ) +
141
- ( command . options . size !== 0 ? ' [' + chalk . yellow ( 'options' ) + ']' : '' ) +
142
- ( command . commands . size !== 0 ? ' [' + chalk . green ( 'command' ) + ']' : '' ) ,
126
+ ' ' + colors . cyan ( commandPath ) +
127
+ args ( command . params , colors . magenta ) +
128
+ ( command . options . size !== 0 ? ' [' + colors . yellow ( 'options' ) + ']' : '' ) +
129
+ ( command . commands . size !== 0 ? ' [' + colors . green ( 'command' ) + ']' : '' ) ,
143
130
commandsHelp ( command ) +
144
131
optionsHelp ( command )
145
132
] . join ( '\n' ) ;
0 commit comments