command-line-args
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -5,2 +5,3 @@ "use strict"; | ||
s = require("string-tools"), | ||
t = require("typical"), | ||
util = require("util"), | ||
@@ -78,3 +79,3 @@ Design = require("nature").Design, | ||
*/ | ||
CliArgs.prototype.parse = function(argv){ | ||
CliArgs.prototype.parse = function(argv, options){ | ||
var shortArg = /^-(\w)/, | ||
@@ -87,4 +88,13 @@ longArg = /^--([\w-]+)/, | ||
argv = argv ? argv.slice(0) : process.argv.slice(2); | ||
if (t.isPlainObject(argv) && options === undefined){ | ||
options = argv; | ||
argv = null; | ||
} | ||
if (argv){ | ||
argv = argv === process.argv ? process.argv.slice(2) : argv.slice(0); | ||
} else { | ||
argv = process.argv.slice(2); | ||
} | ||
function isOption(input){ | ||
@@ -121,3 +131,8 @@ return longArg.test(input) || shortArg.test(input); | ||
} else { | ||
throw new Error("Unexpected option: " + optionName); | ||
if (options && options.unexpectedType){ | ||
self.define({ name: optionName, type: options.unexpectedType }); | ||
setOutput(optionName); | ||
} else { | ||
throw new Error("Unexpected option: " + optionName); | ||
} | ||
} | ||
@@ -124,0 +139,0 @@ }; |
{ | ||
"name": "command-line-args", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "Command-line parser, usage text producer", | ||
@@ -9,3 +9,3 @@ "repository": "https://github.com/75lb/command-line-args.git", | ||
"test": "tap test/*.js", | ||
"docs": "jsdoc2md -t jsdoc2md/README.hbs lib/command-line-args.js > README.md" | ||
"docs": "jsdoc2md --index -t jsdoc2md/README.hbs lib/command-line-args.js > README.md" | ||
}, | ||
@@ -34,4 +34,5 @@ "keywords": [ | ||
"object-tools": "^1.0.0", | ||
"string-tools": "^0.1.4" | ||
"string-tools": "^0.1.4", | ||
"typical": "^1.0.0" | ||
} | ||
} |
@@ -65,10 +65,6 @@ [![view on npm](http://img.shields.io/npm/v/command-line-args.svg)](https://www.npmjs.org/package/command-line-args) | ||
<a name="module_command-line-args"></a> | ||
##command-line-args(options) | ||
A constructor function, taking your desired command-line option definitions as input, returning an instance of `command-line-args` which you can `parse()` or `getUsage()`. | ||
##command-line-args | ||
- options [Array.<OptionDefinition>](#module_command-line-args.OptionDefinition) - list of option definitions | ||
####Example | ||
**Example** | ||
```js | ||
@@ -82,2 +78,7 @@ var cliArgs = require("command-line-args"); | ||
``` | ||
**Symbols** | ||
* [cli.parse([argv])](#module_command-line-args#parse) | ||
* [cli.getUsage(options)](#module_command-line-args#getUsage) | ||
* [\~type: OptionDefinition](#module_command-line-args.OptionDefinition) | ||
<a name="module_command-line-args#parse"></a> | ||
@@ -87,2 +88,3 @@ ###cli.parse([argv]) | ||
**Params** | ||
@@ -92,3 +94,3 @@ - [argv=process.argv] `object` - Optional argv array, pass to override the default `process.argv`. | ||
**Returns**: `object` | ||
####Example | ||
**Example** | ||
Output from `parse()` looks something like this: | ||
@@ -116,13 +118,13 @@ ```js | ||
###cli.getUsage(options) | ||
**Params** | ||
- options `object` - options for template | ||
- options.title `string` - a title | ||
- options.header `string` - a header | ||
- options.footer `string` - a footer | ||
- options.forms `array` - the invocation forms | ||
- title `string` - a title | ||
- header `string` - a header | ||
- footer `string` - a footer | ||
- forms `array` - the invocation forms | ||
**Returns**: `string` | ||
<a name="module_command-line-args.OptionDefinition"></a> | ||
###type: OptionDefinition | ||
###\~type: OptionDefinition | ||
Defines an option | ||
@@ -129,0 +131,0 @@ |
28869
22
657
154
7
+ Addedtypical@^1.0.0