diff --git a/README.md b/README.md index 36331bd..becbd88 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,13 @@ for [node.js](http://nodejs.org/) and [npm](http://github.com/isaacs/npm): By default, nomnom parses [node](http://nodejs.org/)'s `process.argv`. You can also pass in the args: var options = nomnom.parseArgs(opts, {}, ["-xvf", "--atomic=true"]) +Values are JSON parsed, so `--debug=true --count=3 --file=log.txt` would give you: + { debug: true, + count: 3, + file: "log.txt" + } + +### positional args All parsed arguments that don't fit the `-a` or `--atomic` format and aren't attached to an option are positional and can be matched on via the `position`: var opts = { filename: { @@ -45,13 +52,42 @@ All parsed arguments that don't fit the `-a` or `--atomic` format and aren't att var options = nomnom.parseArgs(opts); sys.puts(options.filename); - -Values are JSON parsed, so `--debug=true --count=3 --file=log.txt` would give you: - { debug: true, - count: 3, - file: "log.txt" + +### printing usage +Nomnom prints out a usage message if `--help` or `-h` is an argument. You can disable this with the `printHelp` flag and specify the printing function with `printFunc` if you're not using node: + + nomnom.parseArgs(opts, { printHelp: false }); + +Usage for these options in `test.js`: + var options = { + command: { + position: 0, + help: "either 'test', 'run', or 'xpi'" + }, + config: { + string: '-c FILE, --config=FILE', + help: 'json file with tests to run', + }, + debug: { + string: '-d, --debug', + help: 'use debug mode' + } } + +...would look like this: + Usage: node test.js [options] + + either 'test', 'run', or 'xpi' + + options: + -c FILE, --config=FILE json file with tests to run + -d, --debug use debug mode + +Nomnom can't detect the alias used to run your script. You can use the `script` option to print the correct name instead of e.g. `node test.js`: + nomnom.parseArgs(opts, { script : "test" }); + + + + -Nomnom prints out a usage message if `--help` or `-h` is an argument. You can disable this with the `printHelp` flag and specify the printing function with `printFunc` if you're not using node: - nomnom.parseArgs(opts, {printHelp: false}); diff --git a/lib/nomnom.js b/lib/nomnom.js index 719043f..a39e3fb 100644 --- a/lib/nomnom.js +++ b/lib/nomnom.js @@ -107,7 +107,7 @@ ArgParser.prototype = { helpString : function() { var script = this.script || process.argv[0] + " " + require('path').basename(process.argv[1]); - var str = "usage: " + script; + var str = "Usage: " + script; var positionals = this.options.filter(function(opt) { return opt.position != undefined; @@ -121,13 +121,13 @@ ArgParser.prototype = { str += " [options]\n\n"; positionals.forEach(function(pos) { - str += pos.name + "\t" + (pos.help || "") + "\n"; + str += "<" + pos.name + ">\t\t" + (pos.help || "") + "\n"; }); str += "\noptions:\n" this.options.forEach(function(option) { if(option.position == undefined) - str += option.string + "\t" + (option.help || "") + "\n"; + str += option.string + "\t\t" + (option.help || "") + "\n"; }); return str; }