MCPcopy
hub / github.com/tailwindlabs/tailwindcss / help

Function help

packages/@tailwindcss-cli/src/commands/help/index.ts:5–182  ·  view source on GitHub ↗
({
  render = true,
  invalid,
  usage,
  options,
}: {
  render?: boolean
  invalid?: string
  usage?: string[]
  options?: Arg
})

Source from the content-addressed store, hash-verified

3import { UI, header, highlight, indent, println, wordWrap } from '../../utils/renderer'
4
5export function help({
6 render = true,
7 invalid,
8 usage,
9 options,
10}: {
11 render?: boolean
12 invalid?: string
13 usage?: string[]
14 options?: Arg
15}) {
16 // Available terminal width
17 let width = process.stdout.columns ?? 80
18 let lines: string[] = []
19 let writeLine = render ? println : (value = '') => void lines.push(value)
20
21 // Render header
22 writeLine(header())
23
24 // Render the invalid command
25 if (invalid) {
26 writeLine()
27 writeLine(`${pc.dim('Invalid command:')} ${invalid}`)
28 }
29
30 // Render usage
31 if (usage && usage.length > 0) {
32 writeLine()
33 writeLine(pc.dim('Usage:'))
34 for (let [idx, example] of usage.entries()) {
35 // Split the usage example into the command and its options. This allows
36 // us to wrap the options based on the available width of the terminal.
37 let command = example.slice(0, example.indexOf('['))
38 let options = example.slice(example.indexOf('['))
39
40 // Make the options dimmed, to make them stand out less than the command
41 // itself.
42 options = options.replace(/\[.*?\]/g, (option) => pc.dim(option))
43
44 // The space between the command and the options.
45 let space = 1
46
47 // Wrap the options based on the available width of the terminal.
48 let lines = wordWrap(options, width - UI.indent - command.length - space)
49
50 // Print an empty line between the usage examples if we need to split due
51 // to width constraints. This ensures that the usage examples are visually
52 // separated.
53 //
54 // E.g.: when enough space is available
55 //
56 // ```
57 // Usage:
58 // tailwindcss build [--input input.css] [--output output.css] [--watch] [options...]
59 // tailwindcss other [--watch] [options...]
60 // ```
61 //
62 // E.g.: when not enough space is available

Callers 3

rootHelpFunction · 0.90
runFunction · 0.90
helpMessageFunction · 0.90

Calls 5

headerFunction · 0.90
wordWrapFunction · 0.90
indentFunction · 0.90
highlightFunction · 0.90
entriesMethod · 0.45

Tested by

no test coverage detected