forked from tailwindlabs/tailwindcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp.js
More file actions
85 lines (71 loc) · 1.93 KB
/
help.js
File metadata and controls
85 lines (71 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { forEach, map, padEnd } from 'lodash'
import commands from '.'
import * as constants from '../../constants'
import * as colors from '../colors'
import * as utils from '../utils'
export const usage = 'help [command]'
export const description = 'More information about the command.'
const PADDING_SIZE = 3
/**
* Prints general help.
*/
export function forApp() {
const pad = Math.max(...map(commands, 'usage.length')) + PADDING_SIZE
utils.log()
utils.log('Usage:')
utils.log(' ', colors.bold(constants.cli + ' <command> [options]'))
utils.log()
utils.log('Commands:')
forEach(commands, command => {
utils.log(' ', colors.bold(padEnd(command.usage, pad)), command.description)
})
}
/**
* Prints help for a command.
*
* @param {object} command
*/
export function forCommand(command) {
utils.log()
utils.log('Usage:')
utils.log(' ', colors.bold(constants.cli, command.usage))
utils.log()
utils.log('Description:')
utils.log(' ', colors.bold(command.description))
if (command.options) {
const pad = Math.max(...map(command.options, 'usage.length')) + PADDING_SIZE
utils.log()
utils.log('Options:')
forEach(command.options, option => {
utils.log(' ', colors.bold(padEnd(option.usage, pad)), option.description)
})
}
}
/**
* Prints invalid command error and general help. Kills the process.
*
* @param {string} commandName
*/
export function invalidCommand(commandName) {
utils.error('Invalid command:', colors.command(commandName))
forApp()
utils.die()
}
/**
* Runs the command.
*
* @param {string[]} cliParams
* @return {Promise}
*/
export function run(cliParams) {
return new Promise(resolve => {
utils.header()
const commandName = cliParams[0]
const command = commands[commandName]
!commandName && forApp()
commandName && command && forCommand(command)
commandName && !command && invalidCommand(commandName)
utils.footer()
resolve()
})
}