mdopt
markdown option parsing
Useful in combination with marked-man to ensure your man pages are always up to date by making the docs a core part of the cli's runtime. (related: package.json man).
Check out the test cases, or view the example below to get an idea of what a properly formatted options section looks like.
Example
cli.js
:
const mdopt = ; const readFileSync = ; const md = ; const argv = processargv const argv = ; console;
argv
is a variable that holds a minimist object that has
been populated (aliases, defaults) according to the provided markdown
file.
A sample session might look like this:
$ node cli.js
Error: Missing required option demand
$ node cli.js --demand
Error: Missing required option pghost
$ PGHOST=localhost node demo.js --demand hey hey you you
{ _: [ 'hey', 'hey', 'you', 'you' ],
f: false,
flag: false,
home: '/home/jay',
demand: true,
default: 'foo',
d: 'foo',
pghost: 'localhost' }
And finally what the spec.md
file looks like demonstrating
all available options:
spec.md
# demo -- A demonstration of the features & formatting ## SYNOPSIS sample [flags] `<first>` `<last>` `[pet]` ## OPTIONS ### -f, --flag This is a boolean flag as there is no values thatfollow the flag. It can be accessed with $('f') or$('flag') ### --anything ANYTHING This flag expects a value to come after it. It can be anumber, a string, etc. The type will be auto detectedand the value of $('anything') will be that value. ### -s "VALUE", --string "VALUE" Same as above, except that the value placeholder is inquotes meaning that no type detection is performed, andit is kept as a string. Give it `000123` and it willremain `000123` vs. converting it to a number resultingin `123`. ### --default=SOMETHING, -d SOMETHING (default=foo) It is also possible to set default values. ### --home (default=$HOME) And use environment variables to set thosedefaults. Any default value beginning with a `$` willbe treated as an environment variable. ### --demand (required) We can also demand that a flag should be set. ### --pghost "URI" (required, default=$PGHOST) Combining required and using environment variables asdefaults is a good way to ensure that the value will beset one way or another. ## AUTHORS ... Another section ## BUGS ... Another section. Add as many sections as you want.