Generates a usage guide suitable for a command-line app.
Kind: Exported function
Param | Type | Description |
---|---|---|
sections | Section | Array.<Section> | One or more section objects (content or optionList). |
A Content section comprises a header and one or more lines of content.
Kind: inner typedef of commandLineUsage
Properties
Name | Type | Description |
---|---|---|
header | string | The section header, always bold and underlined. |
content | string | Array.<string> | Array.<object> | Overloaded property, accepting data in one of four formats:
|
raw | boolean | Set to true to avoid indentation and wrapping. Useful for banners. |
Example
Simple string of content. For ansi formatting, use chalk template literal syntax.
{
header: 'A typical app',
content: 'Generates something {rgb(255,200,0).italic very {underline.bgRed important}}.'
}
An array of strings is interpreted as lines, to be joined by the system newline character.
{
header: 'A typical app',
content: [
'First line.',
'Second line.'
]
}
An array of recordset-style objects are rendered in table layout.
{
header: 'A typical app',
content: [
{ colA: 'First row, first column.', colB: 'First row, second column.'},
{ colA: 'Second row, first column.', colB: 'Second row, second column.'}
]
}
An object with data
and options
properties will be passed directly to the underlying table layout module for rendering.
{
header: 'A typical app',
content: {
data: [
{ colA: 'First row, first column.', colB: 'First row, second column.'},
{ colA: 'Second row, first column.', colB: 'Second row, second column.'}
],
options: {
maxWidth: 60
}
}
}
An OptionList section adds a table displaying the supplied option definitions.
Kind: inner typedef of commandLineUsage
Properties
Name | Type | Description |
---|---|---|
[header] | string | The section header, always bold and underlined. |
optionList | Array.<OptionDefinition> | An array of option definition objects. In addition to the regular definition properties, command-line-usage will look for:
|
[group] | string | Array.<string> | If specified, only options from this particular group will be printed. Example. |
[hide] | string | Array.<string> | The names of one of more option definitions to hide from the option list. Example. |
[reverseNameOrder] | boolean | If true, the option alias will be displayed after the name, i.e. |
[tableOptions] | object | An options object suitable for passing into table-layout. See here for an example. |
Example
{
header: 'Options',
optionList: [
{
name: 'help',
alias: 'h',
description: 'Display this usage guide.'
},
{
name: 'src',
description: 'The input files to process',
multiple: true,
defaultOption: true,
typeLabel: '{underline file} ...'
},
{
name: 'timeout',
description: 'Timeout value in ms.',
alias: 't',
typeLabel: '{underline ms}'
}
]
}