azer / show-help

Outputs help for parent package and exits
4 stars 1 forks source link

support template, markdown & bin/usage.md #1

Open Raynos opened 10 years ago

Raynos commented 10 years ago

I have a convention like https://github.com/uber/npm-shrinkwrap/blob/master/bin/help.js and https://github.com/uber/npm-shrinkwrap/blob/master/bin/usage.md for showing help.

The features I use are msee for parsing files that end in .md, reading bin/usage.md and passing in an object to showHelp() where it will use the string-template module to fill in the object.

azer commented 10 years ago

just published a new version if it with more lookup paths including bin/usage.md. now you can also pass show-help a transform function (https://github.com/azer/show-help#options). I clonned your repo and tried this and worked;

diff --git a/bin/help.js b/bin/help.js
index 117ce9f..372f36a 100644
--- a/bin/help.js
+++ b/bin/help.js
@@ -1,21 +1,6 @@
-var path = require('path');
-var fs = require('fs');
 var msee = require('msee');
-var template = require('string-template');
+var help = require('show-help')

-function printHelp(opts) {
-    opts = opts || {};
-
-    var loc = path.join(__dirname, 'usage.md');
-    var content = fs.readFileSync(loc, 'utf8');
-
-    content = template(content, {
-        cmd: opts.cmd || 'npm-shrinkwrap'
-    });
-
-    return console.log(msee.parse(content, {
-        paragraphStart: '\n'
-    }));
+module.exports = function () {
+  help({ transform: msee.parse });
 }
-
-module.exports = printHelp;
Raynos commented 10 years ago

Can I add a { markdown: true } option to show-help to move the msee.parse() and { paragraphStart '\n' } into show-help ?

azer commented 10 years ago

that was my first intend but then noticed that msee has some dependencies that are kinda big for putting in show-help

Raynos commented 10 years ago

I see, it does include all of esprima.

I kind of need to wrap the msee specific stuff in some kind of module otherwise there is not enough benefit in including a show-help module.

We could fix msee to have an optional dependency on cardinal.

azer commented 10 years ago

we can also create a new module like show-help-markdown

Raynos commented 10 years ago

that would work too tbh.