command-line-args
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -1,6 +0,12 @@ | ||
var cliArgs = require('../') | ||
/* | ||
command-line-args parses the command line but does not validate what was collected. | ||
This is one method of testing the values received suit your taste. | ||
*/ | ||
'use strict' | ||
var commandLineArgs = require('../') | ||
var testValue = require('test-value') | ||
var fs = require('fs') | ||
var cli = cliArgs([ | ||
var cli = commandLineArgs([ | ||
{ name: 'help', type: Boolean }, | ||
@@ -13,7 +19,6 @@ { name: 'files', type: String, multiple: true, defaultOption: true }, | ||
var usageForm = {} | ||
usageForm.main = { | ||
/* all supplied files should exist and --log-level should be one from the list */ | ||
var correctUsageForm1 = { | ||
files: function (files) { | ||
return files && files.every(fs.existsSync) | ||
return files && files.length && files.every(fs.existsSync) | ||
}, | ||
@@ -23,12 +28,14 @@ 'log-level': [ 'info', 'warn', 'error', undefined ] | ||
usageForm.help = { | ||
/* passing a single --help flag is also valid */ | ||
var correctUsageForm2 = { | ||
help: true | ||
} | ||
var valid = testValue(options, [ usageForm.main, usageForm.help ]) | ||
/* test the options for usage forms 1 or 2 */ | ||
var valid = testValue(options, [ correctUsageForm1, correctUsageForm2 ]) | ||
if (!valid) { | ||
// exit here | ||
if (valid) { | ||
console.log("your options are valid", options) | ||
} else { | ||
console.log("your options are invalid", options) | ||
} | ||
console.log(valid, options) |
@@ -33,7 +33,7 @@ 'use strict' | ||
* ```js | ||
* var commandLineArgs = require("command-line-args") | ||
* var commandLineArgs = require('command-line-args') | ||
* var cli = commandLineArgs([ | ||
* { name: "file" }, | ||
* { name: "verbose" }, | ||
* { name: "depth"} | ||
* { name: 'file' }, | ||
* { name: 'verbose' }, | ||
* { name: 'depth'} | ||
* ]) | ||
@@ -40,0 +40,0 @@ * ``` |
@@ -48,5 +48,5 @@ 'use strict' | ||
* [ | ||
* { name: "file" }, | ||
* { name: "verbose" }, | ||
* { name: "depth"} | ||
* { name: "file" }, | ||
* { name: "verbose" }, | ||
* { name: "depth"} | ||
* ] | ||
@@ -83,14 +83,14 @@ * ``` | ||
* ```js | ||
* var fs = require("fs") | ||
* var fs = require('fs') | ||
* | ||
* function FileDetails(filename){ | ||
* if (!(this instanceof FileDetails)) return new FileDetails(filename) | ||
* this.filename = filename | ||
* this.exists = fs.existsSync(filename) | ||
* if (!(this instanceof FileDetails)) return new FileDetails(filename) | ||
* this.filename = filename | ||
* this.exists = fs.existsSync(filename) | ||
* } | ||
* | ||
* module.exports = [ | ||
* { name: "file", type: FileDetails }, | ||
* { name: "depth", type: Number } | ||
* ] | ||
* var cli = commandLineArgs([ | ||
* { name: 'file', type: FileDetails }, | ||
* { name: 'depth', type: Number } | ||
* ]) | ||
* ``` | ||
@@ -139,4 +139,4 @@ * | ||
* ```js | ||
* module.exports = [ | ||
* { name: "files", type: String, multiple: true } | ||
* [ | ||
* { name: "files", type: String, multiple: true } | ||
* ] | ||
@@ -160,4 +160,4 @@ * ``` | ||
* ```js | ||
* module.exports = [ | ||
* { name: "files", type: String, multiple: true, defaultOption: true } | ||
* [ | ||
* { name: "files", type: String, multiple: true, defaultOption: true } | ||
* ] | ||
@@ -181,5 +181,5 @@ * ``` | ||
* ```js | ||
* module.exports = [ | ||
* { name: "files", type: String, multiple: true, defaultValue: [ "one.js" ] }, | ||
* { name: "max", type: Number, defaultValue: 3 } | ||
* [ | ||
* { name: "files", type: String, multiple: true, defaultValue: [ "one.js" ] }, | ||
* { name: "max", type: Number, defaultValue: 3 } | ||
* ] | ||
@@ -205,8 +205,8 @@ * ``` | ||
* ```js | ||
* module.exports = [ | ||
* { name: "verbose", group: "standard" }, | ||
* { name: "help", group: [ "standard", "main" ] }, | ||
* { name: "compress", group: [ "server", "main" ] }, | ||
* { name: "static", group: "server" }, | ||
* { name: "debug" } | ||
* [ | ||
* { name: "verbose", group: "standard" }, | ||
* { name: "help", group: [ "standard", "main" ] }, | ||
* { name: "compress", group: [ "server", "main" ] }, | ||
* { name: "static", group: "server" }, | ||
* { name: "debug" } | ||
* ] | ||
@@ -213,0 +213,0 @@ * ``` |
{ | ||
"name": "command-line-args", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "A library to collect command-line args and generate a usage guide.", | ||
@@ -29,9 +29,8 @@ "repository": "https://github.com/75lb/command-line-args.git", | ||
"devDependencies": { | ||
"babel": "^5.8.23", | ||
"coveralls": "^2.11.4", | ||
"istanbul": "^0.3.21", | ||
"jsdoc-to-markdown": "^1.1.1", | ||
"standard": "^5.3.1", | ||
"tape": "^4", | ||
"test-value": "^1.0.0", | ||
"babel": "^5.8.23" | ||
"test-value": "^1.0.0" | ||
}, | ||
@@ -38,0 +37,0 @@ "dependencies": { |
[![view on npm](http://img.shields.io/npm/v/command-line-args.svg)](https://www.npmjs.org/package/command-line-args) | ||
[![npm module downloads per month](http://img.shields.io/npm/dm/command-line-args.svg)](https://www.npmjs.org/package/command-line-args) | ||
[![Build Status](https://travis-ci.org/75lb/command-line-args.svg?branch=rewrite)](https://travis-ci.org/75lb/command-line-args) | ||
[![npm module downloads](http://img.shields.io/npm/dt/command-line-args.svg)](https://www.npmjs.org/package/command-line-args) | ||
[![Build Status](https://travis-ci.org/75lb/command-line-args.svg?branch=master)](https://travis-ci.org/75lb/command-line-args) | ||
[![Coverage Status](https://coveralls.io/repos/75lb/command-line-args/badge.svg?branch=master&service=github)](https://coveralls.io/github/75lb/command-line-args?branch=master) | ||
@@ -22,9 +22,9 @@ [![Dependency Status](https://david-dm.org/75lb/command-line-args.svg)](https://david-dm.org/75lb/command-line-args) | ||
```js | ||
var commandLineArgs = require("command-line-args"); | ||
var commandLineArgs = require('command-line-args'); | ||
var cli = commandLineArgs([ | ||
{ name: "verbose", alias: "v", type: Boolean }, | ||
{ name: "src", type: String, multiple: true, defaultOption: true }, | ||
{ name: "timeout", alias: "t", type: Number } | ||
]); | ||
{ name: 'verbose', alias: 'v', type: Boolean }, | ||
{ name: 'src', type: String, multiple: true, defaultOption: true }, | ||
{ name: 'timeout', alias: 't', type: Number } | ||
]) | ||
``` | ||
@@ -35,3 +35,3 @@ The [`type`](#module_definition--OptionDefinition+type) property is a setter function (the value you receive is the output of this), giving you full control over the value received. | ||
```js | ||
var options = cli.parse(); | ||
var options = cli.parse() | ||
``` | ||
@@ -136,7 +136,7 @@ | ||
```js | ||
var commandLineArgs = require("command-line-args") | ||
var commandLineArgs = require('command-line-args') | ||
var cli = commandLineArgs([ | ||
{ name: "file" }, | ||
{ name: "verbose" }, | ||
{ name: "depth"} | ||
{ name: 'file' }, | ||
{ name: 'verbose' }, | ||
{ name: 'depth'} | ||
]) | ||
@@ -188,5 +188,5 @@ ``` | ||
[ | ||
{ name: "file" }, | ||
{ name: "verbose" }, | ||
{ name: "depth"} | ||
{ name: "file" }, | ||
{ name: "verbose" }, | ||
{ name: "depth"} | ||
] | ||
@@ -221,14 +221,14 @@ ``` | ||
```js | ||
var fs = require("fs") | ||
var fs = require('fs') | ||
function FileDetails(filename){ | ||
if (!(this instanceof FileDetails)) return new FileDetails(filename) | ||
this.filename = filename | ||
this.exists = fs.existsSync(filename) | ||
if (!(this instanceof FileDetails)) return new FileDetails(filename) | ||
this.filename = filename | ||
this.exists = fs.existsSync(filename) | ||
} | ||
module.exports = [ | ||
{ name: "file", type: FileDetails }, | ||
{ name: "depth", type: Number } | ||
] | ||
var cli = commandLineArgs([ | ||
{ name: 'file', type: FileDetails }, | ||
{ name: 'depth', type: Number } | ||
]) | ||
``` | ||
@@ -271,4 +271,4 @@ | ||
```js | ||
module.exports = [ | ||
{ name: "files", type: String, multiple: true } | ||
[ | ||
{ name: "files", type: String, multiple: true } | ||
] | ||
@@ -289,4 +289,4 @@ ``` | ||
```js | ||
module.exports = [ | ||
{ name: "files", type: String, multiple: true, defaultOption: true } | ||
[ | ||
{ name: "files", type: String, multiple: true, defaultOption: true } | ||
] | ||
@@ -307,5 +307,5 @@ ``` | ||
```js | ||
module.exports = [ | ||
{ name: "files", type: String, multiple: true, defaultValue: [ "one.js" ] }, | ||
{ name: "max", type: Number, defaultValue: 3 } | ||
[ | ||
{ name: "files", type: String, multiple: true, defaultValue: [ "one.js" ] }, | ||
{ name: "max", type: Number, defaultValue: 3 } | ||
] | ||
@@ -328,8 +328,8 @@ ``` | ||
```js | ||
module.exports = [ | ||
{ name: "verbose", group: "standard" }, | ||
{ name: "help", group: [ "standard", "main" ] }, | ||
{ name: "compress", group: [ "server", "main" ] }, | ||
{ name: "static", group: "server" }, | ||
{ name: "debug" } | ||
[ | ||
{ name: "verbose", group: "standard" }, | ||
{ name: "help", group: [ "standard", "main" ] }, | ||
{ name: "compress", group: [ "server", "main" ] }, | ||
{ name: "static", group: "server" }, | ||
{ name: "debug" } | ||
] | ||
@@ -336,0 +336,0 @@ ``` |
@@ -8,3 +8,3 @@ var test = require('tape') | ||
test('number multiple: 1', function (t) { | ||
test('type-boolean-multiple: 1', function (t) { | ||
var argv = [ '--array', '--array', '--array' ] | ||
@@ -11,0 +11,0 @@ var result = cliArgs(optionDefinitions).parse(argv) |
@@ -8,7 +8,7 @@ var test = require('tape') | ||
test('type-boolean: different values', function (t) { | ||
test('usage: simple', function (t) { | ||
var cli = cliArgs(optionDefinitions) | ||
var usage = cli.getUsage({ title: 'test' }) | ||
t.ok(/test/.test(usage)) | ||
t.ok(/test/.test(usage), 'title present') | ||
t.end() | ||
}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
77189
6
48
1789