1
1
const chalk = require ( 'chalk' )
2
2
const padEnd = require ( 'string.prototype.padend' )
3
+ const getPadLength = require ( '../util/getPadLength' )
3
4
4
5
module . exports = ( api , options ) => {
5
6
api . registerCommand ( 'help' , args => {
@@ -17,7 +18,7 @@ module.exports = (api, options) => {
17
18
`\n Commands:\n`
18
19
)
19
20
const commands = api . service . commands
20
- const padLength = getLongest ( commands )
21
+ const padLength = getPadLength ( commands )
21
22
for ( const name in commands ) {
22
23
if ( name !== 'help' ) {
23
24
const opts = commands [ name ] . opts || { }
@@ -43,7 +44,7 @@ module.exports = (api, options) => {
43
44
}
44
45
if ( opts . options ) {
45
46
console . log ( `\n Options:\n` )
46
- const padLength = getLongest ( opts . options )
47
+ const padLength = getPadLength ( opts . options )
47
48
for ( const name in opts . options ) {
48
49
console . log ( ` ${
49
50
chalk . blue ( padEnd ( name , padLength ) )
@@ -56,13 +57,3 @@ module.exports = (api, options) => {
56
57
}
57
58
}
58
59
}
59
-
60
- function getLongest ( commands ) {
61
- let longest = 10
62
- for ( const name in commands ) {
63
- if ( name . length + 1 > longest ) {
64
- longest = name . length + 1
65
- }
66
- }
67
- return longest
68
- }
0 commit comments