Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

command-line-usage

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

command-line-usage - npm Package Compare versions

Comparing version 1.0.0-2 to 1.0.0

.travis.yml

2

bin/cli.js

@@ -10,4 +10,4 @@ #!/usr/bin/env node

process.stdout.write(usage(cliOptions, {
console.log(usage(cliOptions, {
viewWidth: process.stdout.columns
}));

@@ -14,5 +14,19 @@ "use strict";

/**
@param {cliOption[]} - the CLI options
@param options {object} - Options
@param [options.title] {string}
@param [options.description] {string}
@param [options.forms] {string|string[]}
@param [options.groups] {object} - if you have groups, only names specified here will appear in the output
@param [options.footer] {string}
@param [options.hide] {string|string[]}
@returns {string}
@alias module:command-line-usage
*/
function usage(cliOptions, options){
options = options || {};
options.hide = a.arrayify(options.hide);
cliOptions = cliOptions || [];
if (!Array.isArray(cliOptions)){

@@ -25,2 +39,9 @@ if (cliOptions.options && cliOptions.data){

/* skip hidden options */
if (options.hide.length){
cliOptions = cliOptions.filter(function(option){
return !a(options.hide).contains(option.name);
});
}
var lines = [];

@@ -30,2 +51,8 @@ lines.addLine = function(line){

};
lines.addRow = function(cliOption){
lines.push({
option: getOptionNames(cliOption),
description: cliOption.description
});
};
lines.addEmpty = function(){

@@ -48,3 +75,3 @@ this.push("");

}
if (cliOptions.length){

@@ -67,17 +94,7 @@ if (options.groups){

}
a(cliOptions).where({ "+group": group }).forEach(function(cliOption){
lines.push({
option: getOptionNames(cliOption),
description: cliOption.description
});
});
a(cliOptions).where({ "+group": group }).forEach(lines.addRow);
lines.addEmpty();
});
} else {
cliOptions.forEach(function(cliOption){
lines.push({
option: getOptionNames(cliOption),
description: cliOption.description
});
});
cliOptions.forEach(lines.addRow);
lines.addEmpty();

@@ -92,3 +109,3 @@ }

return columnLayout(lines, {
var output = columnLayout(lines, {
viewWidth: options.viewWidth || process.stdout.columns,

@@ -103,2 +120,4 @@ padding: {

});
output = output.replace(/\n\n$/, "\n");
return output;
}

@@ -108,4 +127,5 @@

var names = [];
var type = cliOption.type ? cliOption.type.name.toLowerCase() : ""
if (type) type = type === "boolean" ? "" : " <" + type + ">";
var type = cliOption.type ? cliOption.type.name.toLowerCase() : "";
var multiple = cliOption.multiple ? "[]" : "";
if (type) type = type === "boolean" ? "" : " <" + type + multiple + ">";

@@ -112,0 +132,0 @@ if (cliOption.alias) names.push("-" + cliOption.alias);

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

@@ -23,3 +23,2 @@ "repository": "https://github.com/75lb/command-line-usage.git",

"docs": "jsdoc2md -t jsdoc2md/README.hbs lib/*.js > README.md; echo",
"lint": "jshint lib/*.js bin/*.js test/*.js; echo",
"test": "tape test/*.js"

@@ -29,7 +28,11 @@ },

"ansi-escape-sequences": "^2.1.0",
"array-tools": "^2.0.0-0",
"array-tools": "^2",
"column-layout": "^1.0.0",
"object-tools": "^2",
"typical": "^2.2.0"
},
"devDependencies": {
"jsdoc-to-markdown": "^1.1.1",
"tape": "^4.0.0"
}
}
[![view on npm](http://img.shields.io/npm/v/command-line-usage.svg)](https://www.npmjs.org/package/command-line-usage)
[![npm module downloads per month](http://img.shields.io/npm/dm/command-line-usage.svg)](https://www.npmjs.org/package/command-line-usage)
[![Build Status](https://travis-ci.org/75lb/command-line-usage.svg?branch=rewrite)](https://travis-ci.org/75lb/command-line-usage)
[![Dependency Status](https://david-dm.org/75lb/command-line-usage.svg)](https://david-dm.org/75lb/command-line-usage)

@@ -9,66 +10,40 @@

## Synopsis
Where `example/dmd.js` looks like this
Where `example/my-app.js` looks like this
```js
module.exports = {
options: {
title: "dmd",
description: "Generate markdown API documentation",
title: "my-app",
description: "Generates something useful",
forms: [
"$ cat jsdoc-parse-output.json | dmd [<options>]"
"$ cat input.json | my-app [<options>]",
"$ my-app <files>"
],
footer: "Project home: https://github.com/jsdoc2md/dmd"
groups: {
main: {
title: "Main options",
description: "This group contains the most important options."
},
misc: "Miscellaneous"
},
footer: "Project home: https://github.com/me/my-app"
},
data: [
{ name: "template", alias: "t", type: String,
description: "A custom handlebars template file to insert documentation into. The default template is `{{>main}}`."
{ name: "one", alias: "a", type: String, group: "main",
description: "The first option"
},
{ name: "heading-depth", type: Number, alias: "d",
description: "root heading depth, defaults to 2 (`##`)."
{ name: "two", type: Number, alias: "b", group: "main",
description: "The second option"
},
{ name: "plugin", type: Array,
description: "Use an installed package containing helper and/or partial overrides"
{ name: "three", alias: "c", type: String, group: "misc",
description: "The third option"
},
{ name: "helper", type: Array,
description: "handlebars helper files to override or extend the default set"
},
{ name: "partial", type: Array,
description: "handlebars partial files to override or extend the default set"
},
{ name: "example-lang", type: String, alias: "l",
description: "Specifies the default language used in @example blocks (for syntax-highlighting purposes). In gfm mode, each @example is wrapped in a fenced-code block. Example usage: `--example-lang js`. Use the special value `none` for no specific language. While using this option, you can override the supplied language for any @example by specifying the `@lang` subtag, e.g `@example @lang hbs`. Specifying `@example @lang off` will disable code blocks for that example."
},
{ name: "name-format", type: Boolean,
description: "Format identifier names as code"
},
{ name: "no-gfm", type: Boolean,
description: "By default, dmd generates github-flavoured markdown. Not all markdown parsers render gfm correctly. If your generated docs look incorrect on sites other than Github (e.g. npmjs.org) try enabling this option to disable Github-specific syntax. "
},
{ name: "separators", type: Boolean,
description: "Put <hr> breaks between identifiers. Improves readability on bulky docs. "
},
{ name: "module-index-format", type: String, alias: "m",
description: "none, grouped, table, dl"
},
{ name: "global-index-format", type: String, alias: "g",
description: "none, grouped, table, dl"
},
{ name: "param-list-format", type: String, alias: "p",
description: "Two options to render parameter lists: 'list' or 'table' (default). Table format works well in most cases but switch to list if things begin to look crowded / squashed. "
},
{ name: "property-list-format", type: String, alias: "r",
description: "list, table"
},
{ name: "member-index-format", type: String, alias: "c",
description: "grouped, list"
},
{ name: "group-by", type: Array,
description: "a list of fields to group member indexes by"
{ name: "four", type: Number, alias: "d", group: "misc",
description: "The fourth option"
}
]
};
```
This command:
```sh
$ command-line-usage example/dmd.js
$ command-line-usage example/my-app.js
```

@@ -79,37 +54,43 @@

dmd
Generate markdown API documentation
my-app
Generates something useful
Usage
$ cat jsdoc-parse-output.json | dmd [<options>]
$ cat input.json | my-app [<options>]
$ my-app <files>
-t, --template <string> A custom handlebars template file to insert documentation into. The default template is `{{>main}}`.
-d, --heading-depth <number> root heading depth, defaults to 2 (`##`).
--plugin <array> Use an installed package containing helper and/or partial overrides
--helper <array> handlebars helper files to override or extend the default set
--partial <array> handlebars partial files to override or extend the default set
-l, --example-lang <string> Specifies the default language used in @example blocks (for syntax-highlighting purposes). In gfm
mode, each @example is wrapped in a fenced-code block. Example usage: `--example-lang js`. Use the
special value `none` for no specific language. While using this option, you can override the supplied
language for any @example by specifying the `@lang` subtag, e.g `@example @lang hbs`. Specifying
`@example @lang off` will disable code blocks for that example.
--name-format Format identifier names as code
--no-gfm By default, dmd generates github-flavoured markdown. Not all markdown parsers render gfm correctly. If
your generated docs look incorrect on sites other than Github (e.g. npmjs.org) try enabling this
option to disable Github-specific syntax.
--separators Put <hr> breaks between identifiers. Improves readability on bulky docs.
-m, --module-index-format <string> none, grouped, table, dl
-g, --global-index-format <string> none, grouped, table, dl
-p, --param-list-format <string> Two options to render parameter lists: 'list' or 'table' (default). Table format works well in most
cases but switch to list if things begin to look crowded / squashed.
-r, --property-list-format <string> list, table
-c, --member-index-format <string> grouped, list
--group-by <array> a list of fields to group member indexes by
Main options
This group contains the most important options.
Project home: https://github.com/jsdoc2md/dmd
-a, --one <string> The first option
-b, --two <number> The second option
Miscellaneous
-c, --three <string> The third option
-d, --four <number> The fourth option
Project home: https://github.com/me/my-app
```
<a name="module_command-line-usage"></a>
## command-line-usage
<a name="exp_module_command-line-usage--usage"></a>
### usage(cliOptions, options) ⇒ <code>string</code> ⏏
**Kind**: Exported function
| Param | Type | Description |
| --- | --- | --- |
| cliOptions | <code>Array.&lt;cliOption&gt;</code> | the CLI options |
| options | <code>object</code> | Options |
| [options.title] | <code>string</code> | |
| [options.description] | <code>string</code> | |
| [options.forms] | <code>string</code> &#124; <code>Array.&lt;string&gt;</code> | |
| [options.groups] | <code>object</code> | |
| [options.footer] | <code>string</code> | |
| [options.hide] | <code>string</code> &#124; <code>Array.&lt;string&gt;</code> | |
* * *
&copy; 2015 Lloyd Brookes \<75pound@gmail.com\>.
&copy; 2015 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/75lb/jsdoc-to-markdown).
var test = require("tape");
var lib = require("../");
var usage = require("../");
var cliOptions = require("../example/my-app");
test("first", function(t){
test("basic", function(t){
var result = usage(cliOptions);
t.ok(/my-app/.test(result));
t.end();
});
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc