commander-to-markdown

1.2.0 • Public • Published

Coveralls – test coverageTravis – build statusDavid – status of dependenciesCode style: airbnb

 

commander-to-markdown

Render the options of a commander app as markdown

 

Installation

$ npm install commander-to-markdown

 

Usage

Say you have a commander app which looks like this:

app.js

const program = require('commander');
 
program
  .arguments('<address>', 'Address for delivery')
  .option('-p, --peppers', 'Add peppers')
  .option('-P, --pineapple', 'Add pineapple')
  .option('-b, --bbq-sauce', 'Add bbq sauce')
  .option('-c, --cheese [type]', 'Pick the type of cheese', 'marble')
  .parse(process.argv);

commanderToMarkdown is pretty much like the require function – only instead of the app itself, you get the program’s options rendered as markdown:

docs.js

▸ const commanderToMarkdown = require('commander-to-markdown');
 
▸ commanderToMarkdown(`${__dirname}/app`);
◂ '''
#### `<address>`
Address for delivery.
 
#### `-p, --peppers`
Add peppers.
 
#### `-P, --pineapple`
Add pineapple.
 
#### `-b, --bbq-sauce`
Add bbq sauce.
 
#### `-c, --cheese [type]`
Pick the type of cheese. Default: `marble`.
'''

 

Demo

Here’s how it looks rendered.


<address>

Address for delivery.

-p, --peppers

Add peppers.

-P, --pineapple

Add pineapple.

-b, --bbq-sauce

Add bbq sauce.

-c, --cheese [type]

Pick the type of cheese. Default: marble.


This looks especially good when rendered as a manpage with marked-man.

 

Preventing the program from executing

To prevent executing the program, we stub out your require('.') and require('..') with an empty function which returns an object. If that’s not enough for you, you can pass us the option programModules:

commanderToMarkdown(`${__dirname/app}`, { programModules: ['.', './logic'] });

 

Caveats

  • At the moment we only accept an absolute path.

 

License

MIT © Studio B12

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.2.0
    11
    • latest

Version History

Package Sidebar

Install

npm i commander-to-markdown

Weekly Downloads

14

Version

1.2.0

License

MIT

Last publish

Collaborators

  • tomekwi