command-line-usage
Advanced tools
Comparing version 4.1.0 to 5.0.0
'use strict' | ||
const Table = require('table-layout') | ||
const ansi = require('ansi-escape-sequences') | ||
const chalkFormat = require('./chalk-format') | ||
const t = require('typical') | ||
@@ -18,3 +18,3 @@ | ||
if (t.isString(content)) { | ||
const table = new Table({ column: ansi.format(content) }, { | ||
const table = new Table({ column: chalkFormat(content) }, { | ||
padding: defaultPadding, | ||
@@ -27,3 +27,3 @@ maxWidth: 80 | ||
} else if (Array.isArray(content) && content.every(t.isString)) { | ||
const rows = content.map(string => ({ column: ansi.format(string) })) | ||
const rows = content.map(string => ({ column: chalkFormat(string) })) | ||
const table = new Table(rows, { | ||
@@ -78,3 +78,3 @@ padding: defaultPadding, | ||
for (const key in row) { | ||
row[key] = ansi.format(row[key]) | ||
row[key] = chalkFormat(row[key]) | ||
} | ||
@@ -81,0 +81,0 @@ return row |
'use strict' | ||
const Section = require('./section') | ||
const Table = require('table-layout') | ||
const ansi = require('ansi-escape-sequences') | ||
const chalkFormat = require('./chalk-format') | ||
const t = require('typical') | ||
@@ -34,8 +34,8 @@ const arrayify = require('array-back') | ||
return { | ||
option: getOptionNames(def, 'bold', data.reverseNameOrder), | ||
description: ansi.format(def.description) | ||
option: getOptionNames(def, data.reverseNameOrder), | ||
description: chalkFormat(def.description) | ||
} | ||
}) | ||
const table = new Table(rows, { | ||
const tableOptions = data.tableOptions || { | ||
padding: { left: ' ', right: ' ' }, | ||
@@ -46,3 +46,4 @@ columns: [ | ||
] | ||
}) | ||
} | ||
const table = new Table(rows, tableOptions) | ||
this.add(table.renderLines()) | ||
@@ -54,9 +55,10 @@ | ||
function getOptionNames (definition, optionNameStyles, reverseNameOrder) { | ||
function getOptionNames (definition, reverseNameOrder) { | ||
let type = definition.type ? definition.type.name.toLowerCase() : '' | ||
const multiple = definition.multiple ? '[]' : '' | ||
if (type) { | ||
type = type === 'boolean' ? '' : `[underline]{${type}${multiple}}` | ||
type = type === 'boolean' ? '' : `{underline ${type}${multiple}}` | ||
} | ||
type = ansi.format(definition.typeLabel || type) | ||
// console.error(require('util').inspect(definition.typeLabel || type, { depth: 6, colors: true })) | ||
type = chalkFormat(definition.typeLabel || type) | ||
@@ -66,8 +68,8 @@ let result = '' | ||
if (reverseNameOrder) { | ||
result = `${ansi.format(`--${definition.name}`, optionNameStyles)}, ${ansi.format('-' + definition.alias, optionNameStyles)} ${type}` | ||
result = `${chalkFormat(`{bold --${definition.name}}`)}, ${chalkFormat(`{bold -${definition.alias}}`)} ${type}` | ||
} else { | ||
result = `${ansi.format('-' + definition.alias, optionNameStyles)}, ${ansi.format(`--${definition.name} ${type}`, optionNameStyles)}` | ||
result = `${chalkFormat(`{bold -${definition.alias}}`)}, ${chalkFormat(`{bold --${definition.name}} ${type}`)}` | ||
} | ||
} else { | ||
result = `${ansi.format(`--${definition.name}`, optionNameStyles)} ${type}` | ||
result = `${chalkFormat(`{bold --${definition.name}}`)} ${type}` | ||
} | ||
@@ -74,0 +76,0 @@ return result |
'use strict' | ||
const ansi = require('ansi-escape-sequences') | ||
const os = require('os') | ||
const arrayify = require('array-back') | ||
@@ -11,3 +8,5 @@ class Section { | ||
add (content) { | ||
arrayify(content).forEach(line => this.list.push(ansi.format(line))) | ||
const chalkFormat = require('./chalk-format') | ||
const arrayify = require('array-back') | ||
arrayify(content).forEach(line => this.list.push(chalkFormat(line))) | ||
} | ||
@@ -18,4 +17,5 @@ emptyLine () { | ||
header (text) { | ||
const chalk = require('chalk') | ||
if (text) { | ||
this.add(ansi.format(text, [ 'underline', 'bold' ])) | ||
this.add(chalk.underline.bold(text)) | ||
this.emptyLine() | ||
@@ -25,2 +25,3 @@ } | ||
toString () { | ||
const os = require('os') | ||
return this.list.join(os.EOL) | ||
@@ -27,0 +28,0 @@ } |
{ | ||
"name": "command-line-usage", | ||
"author": "Lloyd Brookes <75pound@gmail.com>", | ||
"version": "4.1.0", | ||
"version": "5.0.0", | ||
"description": "Generates command-line usage information", | ||
"repository": "https://github.com/75lb/command-line-usage.git", | ||
"license": "MIT", | ||
"main": "lib/command-line-usage", | ||
"files": [ | ||
@@ -22,8 +21,8 @@ "lib" | ||
"scripts": { | ||
"docs": "jsdoc2md -t jsdoc2md/README.hbs --no-gfm lib/*.js > README.md; echo", | ||
"docs": "jsdoc2md -t jsdoc2md/README.hbs --no-gfm index.js > README.md; echo", | ||
"test": "test-runner test/*.js" | ||
}, | ||
"dependencies": { | ||
"ansi-escape-sequences": "^4.0.0", | ||
"array-back": "^2.0.0", | ||
"chalk": "^2.3.2", | ||
"table-layout": "^0.4.2", | ||
@@ -33,5 +32,5 @@ "typical": "^2.6.1" | ||
"devDependencies": { | ||
"jsdoc-to-markdown": "^3.0.4", | ||
"jsdoc-to-markdown": "^4.0.1", | ||
"test-runner": "^0.5.0" | ||
} | ||
} |
@@ -11,8 +11,6 @@ [![view on npm](http://img.shields.io/npm/v/command-line-usage.svg)](https://www.npmjs.org/package/command-line-usage) | ||
## Synopsis | ||
A usage guide is created by first defining an arbitrary number of sections, e.g. a description section, synopsis, option list, examples, footer etc. Each section has an optional header and some content. Each section must be of type <code><a href="#commandlineusagecontent">content</a></code> or <code><a href="#commandlineusageoptionlist">optionList</a></code>. | ||
A usage guide is created by first defining an arbitrary number of sections, e.g. a description section, synopsis, option list, examples, footer etc. Each section has an optional header, some content and must be of type <code><a href="#commandlineusagecontent">content</a></code> or <code><a href="#commandlineusageoptionlist">optionList</a></code>. This section data is passed to <code><a href="#commandlineusagesections--string-">commandLineUsage()</a></code> which returns a usage guide. | ||
This section data is passed to <code><a href="#commandlineusagesections--string-">commandLineUsage()</a></code> which renders the usage guide. | ||
Inline ansi formatting can be used anywhere within section content using [chalk template literal syntax](https://github.com/chalk/chalk#tagged-template-literal). | ||
Inline ansi formatting can be used anywhere within section content using the formatting syntax described [here](https://github.com/75lb/ansi-escape-sequences#module_ansi-escape-sequences.format). | ||
For example, this script: | ||
@@ -25,3 +23,3 @@ ```js | ||
header: 'A typical app', | ||
content: 'Generates something [italic]{very} important.' | ||
content: 'Generates something {italic very} important.' | ||
}, | ||
@@ -33,3 +31,3 @@ { | ||
name: 'input', | ||
typeLabel: '[underline]{file}', | ||
typeLabel: '{underline file}', | ||
description: 'The input to process.' | ||
@@ -82,4 +80,9 @@ }, | ||
### Advanced optionList layout | ||
The `optionList` layout is fully configurable by setting the `tableOptions` property with an options object suitable for passing into [table-layout](https://github.com/75lb/table-layout#table-). This example overrides the default column widths and adds flame padding. [Code](https://github.com/75lb/command-line-usage/blob/master/example/option-list-options.js). | ||
![usage](https://raw.githubusercontent.com/75lb/command-line-usage/master/example/screens/option-list-options.png) | ||
### Command list | ||
Useful if your app is [command-driven](https://github.com/75lb/command-line-commands), like git or npm. [Code](https://github.com/75lb/command-line-usage/blob/master/example/command-list.js). | ||
Useful if your app is command-driven, like git or npm. [Code](https://github.com/75lb/command-line-usage/blob/master/example/command-list.js). | ||
@@ -164,7 +167,7 @@ ![usage](https://raw.githubusercontent.com/75lb/command-line-usage/master/example/screens/command-list.png) | ||
**Example** | ||
Simple string of content. The syntax for ansi formatting is documented [here](https://github.com/75lb/ansi-escape-sequences#module_ansi-escape-sequences.format). | ||
Simple string of content. For ansi formatting, use [chalk template literal syntax](https://github.com/chalk/chalk#tagged-template-literal). | ||
```js | ||
{ | ||
header: 'A typical app', | ||
content: 'Generates something [italic]{very} important.' | ||
content: 'Generates something {rgb(255,200,0).italic very {underline.bgRed important}}.' | ||
} | ||
@@ -226,6 +229,6 @@ ``` | ||
<tr> | ||
<td>header</td><td><code>string</code></td><td><p>The section header, always bold and underlined.</p> | ||
<td>[header]</td><td><code>string</code></td><td><p>The section header, always bold and underlined.</p> | ||
</td> | ||
</tr><tr> | ||
<td>optionList</td><td><code>Array.<OptionDefinition></code></td><td><p>an array of <a href="https://github.com/75lb/command-line-args#optiondefinition-">option definition</a> objects. In addition to the regular definition properties, command-line-usage will look for:</p> | ||
<td>optionList</td><td><code>Array.<OptionDefinition></code></td><td><p>an array of <a href="https://github.com/75lb/command-line-args/blob/master/doc/option-definition.md">option definition</a> objects. In addition to the regular definition properties, command-line-usage will look for:</p> | ||
<ul> | ||
@@ -237,10 +240,13 @@ <li><code>description</code> - a string describing the option.</li> | ||
</tr><tr> | ||
<td>group</td><td><code>string</code> | <code>Array.<string></code></td><td><p>If specified, only options from this particular group will be printed. <a href="https://github.com/75lb/command-line-usage/blob/master/example/groups.js">Example</a>.</p> | ||
<td>[group]</td><td><code>string</code> | <code>Array.<string></code></td><td><p>If specified, only options from this particular group will be printed. <a href="https://github.com/75lb/command-line-usage/blob/master/example/groups.js">Example</a>.</p> | ||
</td> | ||
</tr><tr> | ||
<td>hide</td><td><code>string</code> | <code>Array.<string></code></td><td><p>The names of one of more option definitions to hide from the option list. <a href="https://github.com/75lb/command-line-usage/blob/master/example/hide.js">Example</a>.</p> | ||
<td>[hide]</td><td><code>string</code> | <code>Array.<string></code></td><td><p>The names of one of more option definitions to hide from the option list. <a href="https://github.com/75lb/command-line-usage/blob/master/example/hide.js">Example</a>.</p> | ||
</td> | ||
</tr><tr> | ||
<td>reverseNameOrder</td><td><code>boolean</code></td><td><p>If true, the option alias will be displayed after the name, i.e. <code>--verbose, -v</code> instead of <code>-v, --verbose</code>).</p> | ||
<td>[reverseNameOrder]</td><td><code>boolean</code></td><td><p>If true, the option alias will be displayed after the name, i.e. <code>--verbose, -v</code> instead of <code>-v, --verbose</code>).</p> | ||
</td> | ||
</tr><tr> | ||
<td>[tableOptions]</td><td><code>object</code></td><td><p>An options object suitable for passing into <a href="https://github.com/75lb/table-layout#table-">table-layout</a>. See <a href="https://github.com/75lb/command-line-usage/blob/master/example/option-list-options.js">here for an example</a>.</p> | ||
</td> | ||
</tr> </tbody> | ||
@@ -259,7 +265,7 @@ </table> | ||
name: 'src', description: 'The input files to process', | ||
multiple: true, defaultOption: true, typeLabel: '[underline]{file} ...' | ||
multiple: true, defaultOption: true, typeLabel: '{underline file} ...' | ||
}, | ||
{ | ||
name: 'timeout', description: 'Timeout value in ms. This description is needlessly long unless you count testing of the description column maxWidth useful.', | ||
alias: 't', typeLabel: '[underline]{ms}' | ||
alias: 't', typeLabel: '{underline ms}' | ||
} | ||
@@ -266,0 +272,0 @@ ] |
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
271
20424
195
1
+ Addedchalk@^2.3.2
+ Addedansi-styles@3.2.1(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedsupports-color@5.5.0(transitive)
- Removedansi-escape-sequences@^4.0.0
- Removedansi-escape-sequences@4.1.0(transitive)
- Removedarray-back@3.1.0(transitive)