Socket
Socket
Sign inDemoInstall

command-line-usage

Package Overview
Dependencies
5
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.5 to 3.0.0

example/assets/example-options.js

230

es5/command-line-usage.js
'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

@@ -7,3 +9,3 @@

var columnLayout = require('column-layout');
var tableLayout = require('table-layout');
var ansi = require('ansi-escape-sequences');

@@ -14,3 +16,2 @@ var os = require('os');

var arrayify = require('array-back');
var wrap = require('wordwrapjs');

@@ -40,2 +41,15 @@ module.exports = getUsage;

}
}, {
key: 'header',
value: function header(text) {
if (text) {
this.add(ansi.format(text, ['underline', 'bold']));
this.emptyLine();
}
}
}, {
key: 'toString',
value: function toString() {
return this.list.join(os.EOL);
}
}]);

@@ -46,61 +60,59 @@

function getUsage(definitions, options) {
options = new UsageOptions(options);
definitions = definitions || [];
function getUsage(sections) {
if (sections && sections.length) {
var _ret = function () {
var output = new Lines();
sections.forEach(function (section) {
if (section.optionList) {
if (section.hide && section.hide.length) {
section.optionList = section.optionList.filter(function (definition) {
return section.hide.indexOf(definition.name) === -1;
});
}
output.header(section.header);
output.add(optionList(section.optionList, section.group));
output.emptyLine();
} else if (section.content) {
output.add(renderSection(section.header, section.content));
} else if (section.banner) {
output.header(section.header);
output.add(section.banner);
}
});
return {
v: '\n' + output
};
}();
var output = new Lines();
output.emptyLine();
if (options.hide && options.hide.length) {
definitions = definitions.filter(function (definition) {
return options.hide.indexOf(definition.name) === -1;
});
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
}
}
if (options.header) {
output.add(renderSection('', options.header));
function optionList(definitions, group) {
if (!definitions || definitions && !definitions.length) {
throw new Error('you must pass option definitions to getUsage.optionList()');
}
var columns = [];
if (options.title || options.description) {
output.add(renderSection(options.title, t.isString(options.description) ? wrap.lines(options.description, { width: 80 }) : options.description));
if (group === '_none') {
definitions = definitions.filter(function (def) {
return !t.isDefined(def.group);
});
} else if (group) {
definitions = definitions.filter(function (def) {
return arrayify(def.group).indexOf(group) > -1;
});
}
if (options.synopsis) {
output.add(renderSection('Synopsis', options.synopsis));
}
definitions.forEach(function (def) {
columns.push({
option: getOptionNames(def, 'bold'),
description: ansi.format(def.description)
});
});
if (definitions.length) {
if (options.groups) {
for (var group in options.groups) {
var val = options.groups[group];
var title = void 0;
var description = void 0;
if (t.isObject(val)) {
title = val.title;
description = val.description;
} else if (t.isString(val)) {
title = val;
} else {
throw new Error('Unexpected group config structure');
}
output.add(renderSection(title, description));
var optionList = getUsage.optionList(definitions, group);
output.add(renderSection(null, optionList, true));
}
} else {
output.add(renderSection('Options', getUsage.optionList(definitions), true));
}
}
if (options.examples) {
output.add(renderSection('Examples', options.examples));
}
if (options.footer) {
output.add(renderSection('', options.footer));
}
return output.list.join(os.EOL);
return tableLayout.lines(columns, {
padding: { left: ' ', right: ' ' },
columns: [{ name: 'option', nowrap: true }, { name: 'description', maxWidth: 80 }]
});
}

@@ -115,3 +127,5 @@

if (definition.alias) names.push(ansi.format('-' + definition.alias, optionNameStyles));
if (definition.alias) {
names.push(ansi.format('-' + definition.alias, optionNameStyles));
}
names.push(ansi.format('--' + definition.name, optionNameStyles) + ' ' + type);

@@ -121,8 +135,7 @@ return names.join(', ');

function renderSection(title, content, skipIndent) {
function renderSection(header, content) {
var lines = new Lines();
if (title) {
lines.add(ansi.format(title, ['underline', 'bold']));
lines.emptyLine();
if (header) {
lines.header(header);
}

@@ -133,35 +146,47 @@

} else {
if (t.isString(content)) {
lines.add(indentString(content));
} else if (Array.isArray(content) && content.every(t.isString)) {
lines.add(skipIndent ? content : indentArray(content));
} else if (Array.isArray(content) && content.every(t.isPlainObject)) {
lines.add(columnLayout.lines(content, {
padding: { left: ' ', right: ' ' }
}));
} else if (t.isPlainObject(content)) {
if (!content.options || !content.data) {
throw new Error('must have an "options" or "data" property\n' + JSON.stringify(content));
}
Object.assign({ padding: { left: ' ', right: ' ' } }, content.options);
lines.add(columnLayout.lines(content.data.map(function (row) {
return formatRow(row);
}), content.options));
} else {
var message = 'invalid input - \'content\' must be a string, array of strings, or array of plain objects:\n\n' + JSON.stringify(content);
throw new Error(message);
}
var _ret2 = function () {
lines.emptyLine();
return lines.list;
var defaultPadding = { left: ' ', right: ' ' };
if (t.isString(content)) {
lines.add(tableLayout.lines({ column: content }, {
padding: defaultPadding,
maxWidth: 80
}));
} else if (Array.isArray(content) && content.every(t.isString)) {
content.forEach(function (row) {
lines.add(tableLayout.lines({ column: row }, {
padding: defaultPadding,
maxWidth: 80
}));
});
lines.add();
} else if (Array.isArray(content) && content.every(t.isPlainObject)) {
lines.add(tableLayout.lines(content, {
padding: defaultPadding
}));
} else if (t.isPlainObject(content)) {
if (!content.options || !content.data) {
throw new Error('must have an "options" or "data" property\n' + JSON.stringify(content));
}
Object.assign({ padding: defaultPadding }, content.options);
lines.add(tableLayout.lines(content.data.map(function (row) {
return ansiFormatRow(row);
}), content.options));
} else {
var message = 'invalid input - \'content\' must be a string, array of strings, or array of plain objects:\n\n' + JSON.stringify(content);
throw new Error(message);
}
lines.emptyLine();
return {
v: lines.list
};
}();
if ((typeof _ret2 === 'undefined' ? 'undefined' : _typeof(_ret2)) === "object") return _ret2.v;
}
}
function indentString(string) {
return ' ' + string;
}
function indentArray(array) {
return array.map(indentString);
}
function formatRow(row) {
function ansiFormatRow(row) {
for (var key in row) {

@@ -171,31 +196,2 @@ row[key] = ansi.format(row[key]);

return row;
}
getUsage.optionList = function (definitions, group) {
if (!definitions || definitions && !definitions.length) {
throw new Error('you must pass option definitions to getUsage.optionList()');
}
var columns = [];
if (group === '_none') {
definitions = definitions.filter(function (def) {
return !t.isDefined(def.group);
});
} else if (group) {
definitions = definitions.filter(function (def) {
return arrayify(def.group).indexOf(group) > -1;
});
}
definitions.forEach(function (def) {
columns.push({
option: getOptionNames(def, 'bold'),
description: ansi.format(def.description)
});
});
return columnLayout.lines(columns, {
padding: { left: ' ', right: ' ' },
columns: [{ name: 'option', nowrap: true }, { name: 'description', maxWidth: 80 }]
});
};
}
const getUsage = require('../')
const ussr = require('./assets/ascii-ussr')
const optionDefinitions = require('./assets/example-options')
const optionDefinitions = [
const sections = [
{
name: 'help', description: 'Display this usage guide.',
alias: 'h', type: Boolean
header: 'Brezhnev',
content: {
options: {
columns: [
{ name: 'one', maxWidth: 40 },
{ name: 'two', width: 40, nowrap: true }
]
},
data: [
{
one: 'On his 70th birthday he was awarded the rank of Marshal of the Soviet Union – the highest military honour in the Soviet Union. After being awarded the medal, he attended an 18th Army Veterans meeting, dressed in a long coat and saying; "Attention, Marshal\'s coming!" He also conferred upon himself the rare [bold]{Order of Victory} in 1978 — the only time the decoration was ever awarded outside of World War II. (This medal was posthumously revoked in 1989 for not meeting the criteria for citation.) \n\nBrezhnev\'s weakness for undeserved medals was proven by his poorly written memoirs recalling his military service during World War II, which treated the little-known and minor Battle of Novorossiysk as the decisive military theatre.',
two: ussr
}
]
}
},
{
name: 'src', description: 'The input files to process',
type: String, multiple: true, defaultOption: true, typeLabel: '[underline]{file} ...'
header: 'Synopsis',
content: [
'$ example [[bold]{--timeout} [underline]{ms}] [bold]{--src} [underline]{file} ...',
'$ example [bold]{--help}'
]
},
{
name: 'timeout', description: 'Timeout value in ms. This description is needlessly long unless you count testing of the description column maxWidth useful.',
alias: 't', type: Number, typeLabel: '[underline]{ms}'
header: 'Options',
optionList: optionDefinitions
}
]
const options = {
title: 'brezhnev',
description: {
options: {
columns: [
{ name: 'one', maxWidth: 40 },
{ name: 'two', width: 40, nowrap: true }
]
},
data: [
{
one: 'On his 70th birthday he was awarded the rank of Marshal of the Soviet Union – the highest military honour in the Soviet Union. After being awarded the medal, he attended an 18th Army Veterans meeting, dressed in a long coat and saying; "Attention, Marshal\'s coming!" He also conferred upon himself the rare [bold]{Order of Victory} in 1978 — the only time the decoration was ever awarded outside of World War II. (This medal was posthumously revoked in 1989 for not meeting the criteria for citation.) \n\nBrezhnev\'s weakness for undeserved medals was proven by his poorly written memoirs recalling his military service during World War II, which treated the little-known and minor Battle of Novorossiysk as the decisive military theatre.',
two: ussr
}
]
},
synopsis: [
'$ example [[bold]{--timeout} [underline]{ms}] [bold]{--src} [underline]{file} ...',
'$ example [bold]{--help}'
]
}
console.log(getUsage(optionDefinitions, options))
console.log(getUsage(sections))
const getUsage = require('../')
const optionDefinitions = require('./assets/example-options')
const optionDefinitions = [
const sections = [
{
name: 'help', description: 'Display this usage guide.',
alias: 'h', type: Boolean
header: 'A typical app',
content: 'Generates something [italic]{very} important.'
},
{
name: 'src', description: 'The input files to process',
type: String, multiple: true, defaultOption: true, typeLabel: '[underline]{file} ...'
header: 'Synopsis',
content: [
'$ example [[bold]{--timeout} [underline]{ms}] [bold]{--src} [underline]{file} ...',
'$ example [bold]{--help}'
]
},
{
name: 'timeout', description: 'Timeout value in ms',
alias: 't', type: Number, typeLabel: '[underline]{ms}'
header: 'Options',
optionList: optionDefinitions
},
{
header: 'Examples',
content: [
{
desc: '1. A concise example. ',
example: '$ example -t 100 lib/*.js'
},
{
desc: '2. A long example. ',
example: '$ example --timeout 100 --src lib/*.js'
},
{
desc: '3. This example will scan space for unknown things. Take cure when scanning space, it could take some time. ',
example: '$ example --src galaxy1.facts galaxy1.facts galaxy2.facts galaxy3.facts galaxy4.facts galaxy5.facts'
}
]
},
{
content: 'Project home: [underline]{https://github.com/me/example}'
}
]
const options = {
title: 'a typical app',
description: 'Generates something very important.',
synopsis: [
'$ example [[bold]{--timeout} [underline]{ms}] [bold]{--src} [underline]{file} ...',
'$ example [bold]{--help}'
],
examples: [
{
desc: '1. A concise example. ',
example: '$ example -t 100 lib/*.js'
},
{
desc: '2. A long example. ',
example: '$ example --timeout 100 --src lib/*.js'
},
{
desc: '3. This example will scan space for unknown things. Take cure when scanning space, it could take some time. ',
example: '$ example --src galaxy1.facts galaxy1.facts galaxy2.facts galaxy3.facts galaxy4.facts galaxy5.facts'
}
],
footer: 'Project home: [underline]{https://github.com/me/example}'
}
console.log(getUsage(optionDefinitions, options))
console.log(getUsage(sections))
const getUsage = require('../')
const wales = require('./assets/ansi-wales').split('\n')
const wales = require('./assets/ansi-wales')
const optionDefinitions = require('./assets/example-options')
const optionDefinitions = [
const sections = [
{
name: 'help', description: 'Display this usage guide.',
alias: 'h', type: Boolean
header: 'A typical app',
content: 'Generates something [italic]{very} important.'
},
{
name: 'src', description: 'The input files to process',
type: String, multiple: true, defaultOption: true, typeLabel: '[underline]{file} ...'
header: 'Synopsis',
content: [
'$ example [[bold]{--timeout} [underline]{ms}] [bold]{--src} [underline]{file} ...',
'$ example [bold]{--help}'
]
},
{
name: 'timeout', description: 'Timeout value in ms',
alias: 't', type: Number, typeLabel: '[underline]{ms}'
header: 'Options',
optionList: optionDefinitions
},
{
banner: [
'[italic]{This app was tested by dragons in Wales.}',
'',
wales
]
}
]
const options = {
title: 'a typical app',
description: 'Generates something very important.',
synopsis: [
'$ example [[bold]{--timeout} [underline]{ms}] [bold]{--src} [underline]{file} ...',
'$ example [bold]{--help}'
],
footer: [
'[italic]{This app was tested by dragons in Wales.}',
''
].concat(wales)
}
console.log(getUsage(optionDefinitions, options))
console.log(getUsage(sections))

@@ -25,14 +25,19 @@ const getUsage = require('../')

const options = {
title: 'a typical app',
description: 'Generates something [italic]{very} important.',
groups: {
main: 'Main options',
_none: {
title: 'Misc',
description: 'Miscelaneous ungrouped options.'
}
const sections = [
{
header: 'A typical app',
content: 'Generates something [italic]{very} important.'
},
{
header: 'Main options',
optionList: optionDefinitions,
group: 'main'
},
{
header: 'Misc',
optionList: optionDefinitions,
group: '_none'
}
}
]
console.log(getUsage(optionDefinitions, options))
console.log(getUsage(sections))
const getUsage = require('../')
const header = require('./assets/ansi-header')
const ansi = require('ansi-escape-sequences')
const optionDefinitions = require('./assets/example-options')
const optionDefinitions = [
const sections = [
{
name: 'help', description: 'Display this usage guide.',
alias: 'h', type: Boolean
banner: ansi.format(header, 'red')
},
{
name: 'src', description: 'The input files to process',
type: String, 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', type: Number, typeLabel: '[underline]{ms}'
header: 'Synopsis',
content: [
'$ example [[bold]{--timeout} [underline]{ms}] [bold]{--src} [underline]{file} ...',
'$ example [bold]{--help}'
]
}
]
const options = {
header: ansi.format(header, 'red'),
synopsis: [
'$ example [[bold]{--timeout} [underline]{ms}] [bold]{--src} [underline]{file} ...',
'$ example [bold]{--help}'
]
}
console.log(getUsage(optionDefinitions, options))
console.log(getUsage(sections))
const getUsage = require('../')
const optionDefinitions = require('./assets/example-options')
const optionDefinitions = [
const usage = getUsage([
{
name: 'help', description: 'Display this usage guide.',
alias: 'h', type: Boolean
header: 'A typical app',
content: 'Generates something [italic]{very} important. This is a rather long, but ultimately inconsequential description intended solely to demonstrate description appearance. '
},
{
name: 'src', description: 'The input files to process',
type: String, multiple: true, defaultOption: true
header: 'Options',
optionList: optionDefinitions
},
{
name: 'timeout', description: 'Timeout value in ms',
alias: 't', type: Number
content: 'Project home: [underline]{https://github.com/me/example}'
}
]
])
const options = {
title: 'a typical app',
description: 'Generates something very important. This is a rather long, but ultimately inconsequential description intended solely to demonstrate description appearance. ',
footer: 'Project home: [underline]{https://github.com/me/example}'
}
console.log(getUsage(optionDefinitions, options))
console.log(usage)
var detect = require('feature-detect-es6')
module.exports = detect.class() && detect.arrowFunction() && detect.templateStrings()
module.exports = detect.all('class', 'arrowFunction', 'templateStrings', 'defaultParamValues')
? require('./lib/command-line-usage')
: require('./es5/command-line-usage')
'use strict'
const columnLayout = require('column-layout')
const tableLayout = require('table-layout')
const ansi = require('ansi-escape-sequences')

@@ -8,3 +8,2 @@ const os = require('os')

const arrayify = require('array-back')
const wrap = require('wordwrapjs')

@@ -23,6 +22,14 @@ /**

}
emptyLine () {
this.list.push('')
}
header (text) {
if (text) {
this.add(ansi.format(text, [ 'underline', 'bold' ]))
this.emptyLine()
}
}
toString () {
return this.list.join(os.EOL)
}
}

@@ -40,65 +47,58 @@

*/
function getUsage (definitions, options) {
options = new UsageOptions(options)
definitions = definitions || []
const output = new Lines()
output.emptyLine()
/* filter out hidden definitions */
if (options.hide && options.hide.length) {
definitions = definitions.filter(definition => options.hide.indexOf(definition.name) === -1)
}
if (options.header) {
output.add(renderSection('', options.header))
}
if (options.title || options.description) {
output.add(renderSection(
options.title,
t.isString(options.description)
? wrap.lines(options.description, { width: 80 })
: options.description
))
}
if (options.synopsis) {
output.add(renderSection('Synopsis', options.synopsis))
}
if (definitions.length) {
if (options.groups) {
for (const group in options.groups) {
const val = options.groups[group]
let title
let description
if (t.isObject(val)) {
title = val.title
description = val.description
} else if (t.isString(val)) {
title = val
} else {
throw new Error('Unexpected group config structure')
function getUsage (sections) {
if (sections && sections.length) {
const output = new Lines()
sections.forEach(section => {
if (section.optionList) {
/* filter out hidden definitions */
if (section.hide && section.hide.length) {
section.optionList = section.optionList.filter(definition => section.hide.indexOf(definition.name) === -1)
}
output.add(renderSection(title, description))
let optionList = getUsage.optionList(definitions, group)
output.add(renderSection(null, optionList, true))
output.header(section.header)
output.add(optionList(section.optionList, section.group))
output.emptyLine()
} else if (section.content) {
output.add(renderSection(section.header, section.content))
} else if (section.banner) {
output.header(section.header)
output.add(section.banner)
}
} else {
output.add(renderSection('Options', getUsage.optionList(definitions), true))
}
})
return `\n${output}`
}
}
if (options.examples) {
output.add(renderSection('Examples', options.examples))
/**
* A helper for getting a column-format list of options and descriptions. Useful for inserting into a custom usage template.
*
* @param {optionDefinition[]} - the definitions to Display
* @param [group] {string} - if specified, will output the options in this group. The special group `'_none'` will return options without a group specified.
* @returns {string[]}
*/
function optionList (definitions, group) {
if (!definitions || (definitions && !definitions.length)) {
throw new Error('you must pass option definitions to getUsage.optionList()')
}
const columns = []
if (options.footer) {
output.add(renderSection('', options.footer))
if (group === '_none') {
definitions = definitions.filter(def => !t.isDefined(def.group))
} else if (group) {
definitions = definitions.filter(def => arrayify(def.group).indexOf(group) > -1)
}
return output.list.join(os.EOL)
definitions.forEach(def => {
columns.push({
option: getOptionNames(def, 'bold'),
description: ansi.format(def.description)
})
})
return tableLayout.lines(columns, {
padding: { left: ' ', right: ' ' },
columns: [
{ name: 'option', nowrap: true },
{ name: 'description', maxWidth: 80 }
]
})
}

@@ -113,3 +113,5 @@

if (definition.alias) names.push(ansi.format('-' + definition.alias, optionNameStyles))
if (definition.alias) {
names.push(ansi.format('-' + definition.alias, optionNameStyles))
}
names.push(ansi.format(`--${definition.name}`, optionNameStyles) + ' ' + type)

@@ -119,8 +121,7 @@ return names.join(', ')

function renderSection (title, content, skipIndent) {
function renderSection (header, content) {
const lines = new Lines()
if (title) {
lines.add(ansi.format(title, [ 'underline', 'bold' ]))
lines.emptyLine()
if (header) {
lines.header(header)
}

@@ -131,10 +132,29 @@

} else {
const defaultPadding = { left: ' ', right: ' ' }
/* string content */
if (t.isString(content)) {
lines.add(indentString(content))
lines.add(tableLayout.lines({ column: content }, {
padding: defaultPadding,
maxWidth: 80
}))
/* array of strings */
} else if (Array.isArray(content) && content.every(t.isString)) {
lines.add(skipIndent ? content : indentArray(content))
content.forEach(row => {
lines.add(tableLayout.lines({ column: row }, {
padding: defaultPadding,
maxWidth: 80
}))
})
lines.add()
/* array of objects (use column layout) */
} else if (Array.isArray(content) && content.every(t.isPlainObject)) {
lines.add(columnLayout.lines(content, {
padding: { left: ' ', right: ' ' }
lines.add(tableLayout.lines(content, {
padding: defaultPadding
}))
/* { options: object, content: object[] } */
} else if (t.isPlainObject(content)) {

@@ -145,7 +165,7 @@ if (!content.options || !content.data) {

Object.assign(
{ padding: { left: ' ', right: ' ' } },
{ padding: defaultPadding },
content.options
)
lines.add(columnLayout.lines(
content.data.map(row => formatRow(row)),
lines.add(tableLayout.lines(
content.data.map(row => ansiFormatRow(row)),
content.options

@@ -163,9 +183,3 @@ ))

function indentString (string) {
return ' ' + string
}
function indentArray (array) {
return array.map(indentString)
}
function formatRow (row) {
function ansiFormatRow (row) {
for (const key in row) {

@@ -176,37 +190,1 @@ row[key] = ansi.format(row[key])

}
/**
* A helper for getting a column-format list of options and descriptions. Useful for inserting into a custom usage template.
*
* @param {optionDefinition[]} - the definitions to Display
* @param [group] {string} - if specified, will output the options in this group. The special group `'_none'` will return options without a group specified.
* @returns {string[]}
*/
getUsage.optionList = function (definitions, group) {
if (!definitions || (definitions && !definitions.length)) {
throw new Error('you must pass option definitions to getUsage.optionList()')
}
const columns = []
if (group === '_none') {
definitions = definitions.filter(def => !t.isDefined(def.group))
} else if (group) {
definitions = definitions.filter(def => arrayify(def.group).indexOf(group) > -1)
}
definitions
.forEach(def => {
columns.push({
option: getOptionNames(def, 'bold'),
description: ansi.format(def.description)
})
})
return columnLayout.lines(columns, {
padding: { left: ' ', right: ' ' },
columns: [
{ name: 'option', nowrap: true },
{ name: 'description', maxWidth: 80 }
]
})
}

@@ -76,3 +76,3 @@ 'use strict'

/**
* If you want to hide certain options from the output, specify their names here. This is sometimes used to hide the `defaultOption`.
* If you want to hide certain options from the output, specify their names here. This is sometimes used to hide deprecated options or the `defaultOption`.
* @type {string|string[]}

@@ -104,3 +104,3 @@ * @example

* ```
* .. or an array of objects. In which case, it will be formatted by [column-layout](https://github.com/75lb/column-layout):
* .. or an array of objects. In which case, it will be formatted by [table-layout](https://github.com/75lb/table-layout):
* ```js

@@ -114,3 +114,3 @@ * {

* ```
* If you want set specific column-layout options, pass an object with two properties: `options` and `data`.
* If you want set specific table-layout options, pass an object with two properties: `options` and `data`.
* ```js

@@ -117,0 +117,0 @@ * {

{
"name": "command-line-usage",
"author": "Lloyd Brookes <75pound@gmail.com>",
"version": "2.0.5",
"version": "3.0.0",
"description": "Generates command-line usage information",

@@ -26,6 +26,5 @@ "repository": "https://github.com/75lb/command-line-usage.git",

"array-back": "^1.0.3",
"column-layout": "^2.1.1",
"feature-detect-es6": "^1.2.0",
"typical": "^2.4.2",
"wordwrapjs": "^1.2.0"
"table-layout": "~0.2.0",
"feature-detect-es6": "^1.3.0",
"typical": "^2.4.2"
},

@@ -32,0 +31,0 @@ "devDependencies": {

@@ -40,3 +40,3 @@ [![view on npm](http://img.shields.io/npm/v/command-line-usage.svg)](https://www.npmjs.org/package/command-line-usage)

### Examples (column layout)
A list of `examples` is added. In this case the example list is defined as an array of objects (each with consistently named properties) so will be formatted by [column-layout](https://github.com/75lb/column-layout). [Code](https://github.com/75lb/command-line-usage/blob/master/example/examples.js).
A list of `examples` is added. In this case the example list is defined as an array of objects (each with consistently named properties) so will be formatted by [table-layout](https://github.com/75lb/table-layout). [Code](https://github.com/75lb/command-line-usage/blob/master/example/examples.js).

@@ -58,8 +58,8 @@ ![usage](https://raw.githubusercontent.com/75lb/command-line-usage/master/example/screens/example-columns.png)

* [command-line-usage](#module_command-line-usage)
* [getUsage(definitions, options)](#exp_module_command-line-usage--getUsage) ⇒ <code>string</code> ⏏
* [.optionList(definitions, [group])](#module_command-line-usage--getUsage.optionList) ⇒ <code>Array.&lt;string&gt;</code>
* [getUsage(sections, options)](#exp_module_command-line-usage--getUsage) ⇒ <code>string</code> ⏏
* [~optionList(definitions, [group])](#module_command-line-usage--getUsage..optionList) ⇒ <code>Array.&lt;string&gt;</code>
<a name="exp_module_command-line-usage--getUsage"></a>
### getUsage(definitions, options) ⇒ <code>string</code> ⏏
### getUsage(sections, options) ⇒ <code>string</code> ⏏
**Kind**: Exported function

@@ -74,3 +74,3 @@ <table>

<tr>
<td>definitions</td><td><code>Array.&lt;optionDefinition&gt;</code></td><td><p>an array of <a href="https://github.com/75lb/command-line-args#exp_module_definition--OptionDefinition">option definition</a> objects. In addition to the regular definition properties, command-line-usage will look for:</p>
<td>sections</td><td><code>Array.&lt;optionDefinition&gt;</code></td><td><p>an array of <a href="https://github.com/75lb/command-line-args#exp_module_definition--OptionDefinition">option definition</a> objects. In addition to the regular definition properties, command-line-usage will look for:</p>
<ul>

@@ -87,8 +87,8 @@ <li><code>description</code> - a string describing the option.</li>

<a name="module_command-line-usage--getUsage.optionList"></a>
<a name="module_command-line-usage--getUsage..optionList"></a>
#### getUsage.optionList(definitions, [group]) ⇒ <code>Array.&lt;string&gt;</code>
#### getUsage~optionList(definitions, [group]) ⇒ <code>Array.&lt;string&gt;</code>
A helper for getting a column-format list of options and descriptions. Useful for inserting into a custom usage template.
**Kind**: static method of <code>[getUsage](#exp_module_command-line-usage--getUsage)</code>
**Kind**: inner method of <code>[getUsage](#exp_module_command-line-usage--getUsage)</code>
<table>

@@ -195,3 +195,3 @@ <thead>

### options.hide : <code>string</code> &#124; <code>Array.&lt;string&gt;</code>
If you want to hide certain options from the output, specify their names here. This is sometimes used to hide the `defaultOption`.
If you want to hide certain options from the output, specify their names here. This is sometimes used to hide deprecated options or the `defaultOption`.

@@ -224,3 +224,3 @@ **Kind**: instance property of <code>[UsageOptions](#exp_module_usage-options--UsageOptions)</code>

```
.. or an array of objects. In which case, it will be formatted by [column-layout](https://github.com/75lb/column-layout):
.. or an array of objects. In which case, it will be formatted by [table-layout](https://github.com/75lb/table-layout):
```js

@@ -234,3 +234,3 @@ {

```
If you want set specific column-layout options, pass an object with two properties: `options` and `data`.
If you want set specific table-layout options, pass an object with two properties: `options` and `data`.
```js

@@ -237,0 +237,0 @@ {

var test = require('tape')
var getUsage = require('../')
test('getUsage(definitions, options)', function (t) {
test('getUsage(sections)', function (t) {
var definitions = [

@@ -20,8 +20,14 @@ {

var options = {
title: 'a typical app',
description: 'Generates something very important.'
}
var sections = [
{
header: 'a typical app',
content: 'Generates something very important.'
},
{
header: 'Option list',
optionList: definitions
}
]
var result = getUsage(definitions, options)
var result = getUsage(sections)
t.ok(/a typical app/.test(result))

@@ -32,23 +38,1 @@ t.ok(/Generates something very important/.test(result))

})
test('getUsage.optionList()', function (t) {
var definitions = [
{ name: 'one', description: 'one', group: 'one' },
{ name: 'two', description: 'two', group: 'one' },
{ name: 'three', description: 'three' }
]
t.deepEqual(getUsage.optionList(definitions), [
' \x1b[1m--one\x1b[0m one ',
' \x1b[1m--two\x1b[0m two ',
' \x1b[1m--three\x1b[0m three '
])
t.deepEqual(getUsage.optionList(definitions, 'one'), [
' \x1b[1m--one\x1b[0m one ',
' \x1b[1m--two\x1b[0m two '
])
t.deepEqual(getUsage.optionList(definitions, '_none'), [
' \x1b[1m--three\x1b[0m three '
])
t.end()
})

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc