diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-10-10 03:43:44 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-10-10 03:43:44 +0200 |
commit | abd94a7f5a50f43c797a11b53549ae48fff667c3 (patch) | |
tree | ab8ed457f65cdd72e13e0571d2975729428f1551 /node_modules/nomnom | |
parent | a0247c6a3fd6a09a41a7e35a3441324c4dcb58be (diff) | |
download | wallet-core-abd94a7f5a50f43c797a11b53549ae48fff667c3.tar.xz |
add node_modules to address #4364
Diffstat (limited to 'node_modules/nomnom')
26 files changed, 2400 insertions, 0 deletions
diff --git a/node_modules/nomnom/.npmignore b/node_modules/nomnom/.npmignore new file mode 100644 index 000000000..3c3629e64 --- /dev/null +++ b/node_modules/nomnom/.npmignore @@ -0,0 +1 @@ +node_modules diff --git a/node_modules/nomnom/LICENSE b/node_modules/nomnom/LICENSE new file mode 100644 index 000000000..8092929fe --- /dev/null +++ b/node_modules/nomnom/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2010 Heather Arthur + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/nomnom/README.md b/node_modules/nomnom/README.md new file mode 100644 index 000000000..5864a0956 --- /dev/null +++ b/node_modules/nomnom/README.md @@ -0,0 +1,325 @@ +# nomnom +nomnom is an option parser for node. It noms your args and gives them back to you in a hash. + +```javascript +var opts = require("nomnom") + .option('debug', { + abbr: 'd', + flag: true, + help: 'Print debugging info' + }) + .option('config', { + abbr: 'c', + default: 'config.json', + help: 'JSON file with tests to run' + }) + .option('version', { + flag: true, + help: 'print version and exit', + callback: function() { + return "version 1.2.4"; + } + }) + .parse(); + +if (opts.debug) + // do stuff +``` + +You don't have to specify anything if you don't want to: + +```javascript +var opts = require("nomnom").parse(); + +var url = opts[0]; // get the first positional arg +var file = opts.file // see if --file was specified +var verbose = opts.v // see if -v was specified +var extras = opts._ // get an array of the unmatched, positional args +``` + +# Install +for [node.js](http://nodejs.org/) and [npm](http://github.com/isaacs/npm): + + npm install nomnom + +# More Details +Nomnom supports args like `-d`, `--debug`, `--no-debug`, `--file=test.txt`, `--file test.txt`, `-f test.txt`, `-xvf`, and positionals. Positionals are arguments that don't fit the `-a` or `--atomic` format and aren't attached to an option. + +Values are JSON parsed, so `--debug=true --count=3 --file=log.txt` would give you: + +``` +{ + "debug": true, + "count": 3, + "file": "log.txt" +} +``` + +# Commands +Nomnom supports command-based interfaces (e.g. with git: `git add -p` and `git rebase -i` where `add` and `rebase` are the commands): + +```javascript +var parser = require("nomnom"); + +parser.command('browser') + .callback(function(opts) { + runBrowser(opts.url); + }) + .help("run browser tests"); + +parser.command('sanity') + .option('outfile', { + abbr: 'o', + help: "file to write results to" + }) + .option('config', { + abbr: 'c', + default: 'config.json', + help: "json manifest of tests to run" + }) + .callback(function(opts) { + runSanity(opts.filename); + }) + .help("run the sanity tests") + +parser.parse(); +``` + +Each command generates its own usage message when `-h` or `--help` is specified with the command. + +# Usage +Nomnom prints out a usage message if `--help` or `-h` is an argument. Usage for these options in `test.js`: + +```javascript +var opts = require("nomnom") + .script("runtests") + .options({ + path: { + position: 0, + help: "Test file to run", + list: true + }, + config: { + abbr: 'c', + metavar: 'FILE', + help: "Config file with tests to run" + }, + debug: { + abbr: 'd', + flag: true, + help: "Print debugging info" + } + }).parse(); +``` + +...would look like this: + + usage: runtests <path>... [options] + + path Test file to run + + options: + -c FILE, --config FILE Config file with tests to run + -d, --debug Print debugging info + +# Options +You can either add a specification for an option with `nomnom.option('name', spec)` or pass the specifications to `nomnom.options()` as a hash keyed on option name. Each option specification can have the following fields: + +#### abbr and full +`abbr` is the single character string to match to this option, `full` is the full-length string (defaults to the name of the option). + +This option matches `-d` and `--debug` on the command line: + +```javascript +nomnom.option('debug', { + abbr: 'd' +}) +``` + +This option matches `-n 3`, `--num-lines 12` on the command line: + +```javascript +nomnom.option('numLines', { + abbr: 'n', + full: 'num-lines' +}) +``` + +#### flag + +If this is set to true, the option acts as a flag and doesn't swallow the next value on the command line. Default is `false`, so normally if you had a command line `--config test.js`, `config` would get a value of `test.js` in the options hash. Whereas if you specify: + +```javascript +nomnom.option('config', { + flag: true +}) +``` + +`config` would get a value of `true` in the options hash, and `test.js` would be a free positional arg. + +#### metavar + +`metavar` is used in the usage printout e.g. `"PATH"` in `"-f PATH, --file PATH"`. + +#### string + +A shorthand for `abbr`, `full`, and `metavar`. For example, to attach an option to `-c` and `--config` use a `string: "-c FILE, --config=FILE"` + +#### help + +A string description of the option for the usage printout. + +#### default + +The value to give the option if it's not specified in the arguments. + +#### type + +If you don't want the option JSON-parsed, specify type `"string"`. + +#### callback + +A callback that will be executed as soon as the option is encountered. If the callback returns a string it will print the string and exit: + +```javascript +nomnom.option('count', { + callback: function(count) { + if (count != parseInt(count)) { + return "count must be an integer"; + } + } +}) +``` + +#### position + +The position of the option if it's a positional argument. If the option should be matched to the first positional arg use position `0`, etc. + +#### list + +Specifies that the option is a list. Appending can be achieved by specifying the arg more than once on the command line: + + node test.js --file=test1.js --file=test2.js + +If the option has a `position` and `list` is `true`, all positional args including and after `position` will be appended to the array. + +#### required + +If this is set to `true` and the option isn't in the args, a message will be printed and the program will exit. + +#### choices + +A list of the possible values for the option (e.g. `['run', 'test', 'open']`). If the parsed value isn't in the list a message will be printed and the program will exit. + +#### transform + +A function that takes the value of the option as entered and returns a new value that will be seen as the value of the option. + +```javascript +nomnom.option('date', { + abbr: 'd', + transform: function(timestamp) { + return new Date(timestamp); + } +}) +``` + +#### hidden + +Option won't be printed in the usage + + +# Parser interface +`require("nomnom")` will give you the option parser. You can also make an instance of a parser with `require("nomnom")()`. You can chain any of these functions off of a parser: + +#### option + +Add an option specification with the given name: + +```javascript +nomnom.option('debug', { + abbr: 'd', + flag: true, + help: "Print debugging info" +}) +``` + +#### options + +Add options as a hash keyed by option name, good for a cli with tons of options like [this example](http://github.com/harthur/replace/blob/master/bin/replace.js): + +```javascript +nomnom.options({ + debug: { + abbr: 'd', + flag: true, + help: "Print debugging info" + }, + fruit: { + help: "Fruit to buy" + } +}) +``` + +#### usage + +The string that will override the default generated usage message. + +#### help + +A string that is appended to the usage. + +#### script + +Nomnom can't detect the alias used to run your script. You can use `script` to provide the correct name for the usage printout instead of e.g. `node test.js`. + +#### printer + +Overrides the usage printing function. + +#### command + +Takes a command name and gives you a command object on which you can chain command options. + +#### nocommand + +Gives a command object that will be used when no command is called. + +#### nocolors + +Disables coloring of the usage message. + +#### parse + +Parses node's `process.argv` and returns the parsed options hash. You can also provide argv: + +```javascript +var opts = nomnom.parse(["-xvf", "--atomic=true"]) +``` + +#### nom + +The same as `parse()`. + +# Command interface +A command is specified with `nomnom.command('name')`. All these functions can be chained on a command: + +#### option + +Add an option specifically for this command. + +#### options + +Add options for this command as a hash of options keyed by name. + +#### callback + +A callback that will be called with the parsed options when the command is used. + +#### help + +A help string describing the function of this command. + +#### usage + +Override the default generated usage string for this command. diff --git a/node_modules/nomnom/node_modules/.bin/strip-ansi b/node_modules/nomnom/node_modules/.bin/strip-ansi new file mode 120000 index 000000000..b65c9f81d --- /dev/null +++ b/node_modules/nomnom/node_modules/.bin/strip-ansi @@ -0,0 +1 @@ +../strip-ansi/cli.js
\ No newline at end of file diff --git a/node_modules/nomnom/node_modules/ansi-styles/ansi-styles.js b/node_modules/nomnom/node_modules/ansi-styles/ansi-styles.js new file mode 100644 index 000000000..3da548c40 --- /dev/null +++ b/node_modules/nomnom/node_modules/ansi-styles/ansi-styles.js @@ -0,0 +1,38 @@ +'use strict'; +var styles = module.exports; + +var codes = { + reset: [0, 0], + + bold: [1, 22], + italic: [3, 23], + underline: [4, 24], + inverse: [7, 27], + strikethrough: [9, 29], + + black: [30, 39], + red: [31, 39], + green: [32, 39], + yellow: [33, 39], + blue: [34, 39], + magenta: [35, 39], + cyan: [36, 39], + white: [37, 39], + gray: [90, 39], + + bgBlack: [40, 49], + bgRed: [41, 49], + bgGreen: [42, 49], + bgYellow: [43, 49], + bgBlue: [44, 49], + bgMagenta: [45, 49], + bgCyan: [46, 49], + bgWhite: [47, 49] +}; + +Object.keys(codes).forEach(function (key) { + var val = codes[key]; + var style = styles[key] = {}; + style.open = '\x1b[' + val[0] + 'm'; + style.close = '\x1b[' + val[1] + 'm'; +}); diff --git a/node_modules/nomnom/node_modules/ansi-styles/package.json b/node_modules/nomnom/node_modules/ansi-styles/package.json new file mode 100644 index 000000000..99aa23f07 --- /dev/null +++ b/node_modules/nomnom/node_modules/ansi-styles/package.json @@ -0,0 +1,109 @@ +{ + "_args": [ + [ + { + "raw": "ansi-styles@~1.0.0", + "scope": null, + "escapedName": "ansi-styles", + "name": "ansi-styles", + "rawSpec": "~1.0.0", + "spec": ">=1.0.0 <1.1.0", + "type": "range" + }, + "/home/dold/repos/taler/wallet-webex/node_modules/nomnom/node_modules/chalk" + ] + ], + "_from": "ansi-styles@>=1.0.0 <1.1.0", + "_id": "ansi-styles@1.0.0", + "_inCache": true, + "_location": "/nomnom/ansi-styles", + "_npmUser": { + "name": "sindresorhus", + "email": "sindresorhus@gmail.com" + }, + "_npmVersion": "1.3.15", + "_phantomChildren": {}, + "_requested": { + "raw": "ansi-styles@~1.0.0", + "scope": null, + "escapedName": "ansi-styles", + "name": "ansi-styles", + "rawSpec": "~1.0.0", + "spec": ">=1.0.0 <1.1.0", + "type": "range" + }, + "_requiredBy": [ + "/nomnom/chalk" + ], + "_resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-1.0.0.tgz", + "_shasum": "cb102df1c56f5123eab8b67cd7b98027a0279178", + "_shrinkwrap": null, + "_spec": "ansi-styles@~1.0.0", + "_where": "/home/dold/repos/taler/wallet-webex/node_modules/nomnom/node_modules/chalk", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "http://sindresorhus.com" + }, + "bugs": { + "url": "https://github.com/sindresorhus/ansi-styles/issues" + }, + "dependencies": {}, + "description": "ANSI escape codes for colorizing strings in the terminal", + "devDependencies": { + "mocha": "~1.12.0" + }, + "directories": {}, + "dist": { + "shasum": "cb102df1c56f5123eab8b67cd7b98027a0279178", + "tarball": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-1.0.0.tgz" + }, + "engines": { + "node": ">=0.8.0" + }, + "files": [ + "ansi-styles.js" + ], + "homepage": "https://github.com/sindresorhus/ansi-styles", + "keywords": [ + "ansi", + "styles", + "color", + "colour", + "colors", + "terminal", + "console", + "cli", + "string", + "tty", + "escape", + "formatting", + "rgb", + "256", + "shell", + "xterm", + "log", + "logging", + "command-line", + "text" + ], + "license": "MIT", + "main": "ansi-styles", + "maintainers": [ + { + "name": "sindresorhus", + "email": "sindresorhus@gmail.com" + } + ], + "name": "ansi-styles", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git://github.com/sindresorhus/ansi-styles.git" + }, + "scripts": { + "test": "mocha" + }, + "version": "1.0.0" +} diff --git a/node_modules/nomnom/node_modules/ansi-styles/readme.md b/node_modules/nomnom/node_modules/ansi-styles/readme.md new file mode 100644 index 000000000..4ac8cbd0a --- /dev/null +++ b/node_modules/nomnom/node_modules/ansi-styles/readme.md @@ -0,0 +1,65 @@ +# ansi-styles [![Build Status](https://secure.travis-ci.org/sindresorhus/ansi-styles.png?branch=master)](http://travis-ci.org/sindresorhus/ansi-styles) + +> [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles) for colorizing strings in the terminal. + +You probably want the higher-level [chalk](https://github.com/sindresorhus/chalk) module for styling your strings. + +![screenshot](screenshot.png) + + +## Install + +Install with [npm](https://npmjs.org/package/ansi-styles): `npm install --save ansi-styles` + + +## Example + +```js +var ansi = require('ansi-styles'); + +console.log(ansi.green.open + 'Hello world!' + ansi.green.close); +``` + +## API + +Each style has an `open` and `close` property. + + +## Styles + +### General + +- reset +- bold +- italic +- underline +- inverse +- strikethrough + +### Text colors + +- black +- red +- green +- yellow +- blue +- magenta +- cyan +- white +- gray + +### Background colors + +- bgBlack +- bgRed +- bgGreen +- bgYellow +- bgBlue +- bgMagenta +- bgCyan +- bgWhite + + +## License + +MIT © [Sindre Sorhus](http://sindresorhus.com) diff --git a/node_modules/nomnom/node_modules/chalk/index.js b/node_modules/nomnom/node_modules/chalk/index.js new file mode 100644 index 000000000..a21f70223 --- /dev/null +++ b/node_modules/nomnom/node_modules/chalk/index.js @@ -0,0 +1,63 @@ +'use strict'; +var ansi = require('ansi-styles'); +var stripAnsi = require('strip-ansi'); +var hasColor = require('has-color'); +var defineProps = Object.defineProperties; +var chalk = module.exports; + +var styles = (function () { + var ret = {}; + + ansi.grey = ansi.gray; + + Object.keys(ansi).forEach(function (key) { + ret[key] = { + get: function () { + this._styles.push(key); + return this; + } + }; + }); + + return ret; +})(); + +function init() { + var ret = {}; + + Object.keys(styles).forEach(function (name) { + ret[name] = { + get: function () { + var obj = defineProps(function self() { + var str = [].slice.call(arguments).join(' '); + + if (!chalk.enabled) { + return str; + } + + return self._styles.reduce(function (str, name) { + var code = ansi[name]; + return str ? code.open + str + code.close : ''; + }, str); + }, styles); + + obj._styles = []; + + return obj[name]; + } + } + }); + + return ret; +} + +defineProps(chalk, init()); + +chalk.styles = ansi; +chalk.stripColor = stripAnsi; +chalk.supportsColor = hasColor; + +// detect mode if not set manually +if (chalk.enabled === undefined) { + chalk.enabled = chalk.supportsColor; +} diff --git a/node_modules/nomnom/node_modules/chalk/package.json b/node_modules/nomnom/node_modules/chalk/package.json new file mode 100644 index 000000000..486da5c1b --- /dev/null +++ b/node_modules/nomnom/node_modules/chalk/package.json @@ -0,0 +1,111 @@ +{ + "_args": [ + [ + { + "raw": "chalk@~0.4.0", + "scope": null, + "escapedName": "chalk", + "name": "chalk", + "rawSpec": "~0.4.0", + "spec": ">=0.4.0 <0.5.0", + "type": "range" + }, + "/home/dold/repos/taler/wallet-webex/node_modules/nomnom" + ] + ], + "_from": "chalk@>=0.4.0 <0.5.0", + "_id": "chalk@0.4.0", + "_inCache": true, + "_location": "/nomnom/chalk", + "_npmUser": { + "name": "sindresorhus", + "email": "sindresorhus@gmail.com" + }, + "_npmVersion": "1.3.17", + "_phantomChildren": {}, + "_requested": { + "raw": "chalk@~0.4.0", + "scope": null, + "escapedName": "chalk", + "name": "chalk", + "rawSpec": "~0.4.0", + "spec": ">=0.4.0 <0.5.0", + "type": "range" + }, + "_requiredBy": [ + "/nomnom" + ], + "_resolved": "https://registry.npmjs.org/chalk/-/chalk-0.4.0.tgz", + "_shasum": "5199a3ddcd0c1efe23bc08c1b027b06176e0c64f", + "_shrinkwrap": null, + "_spec": "chalk@~0.4.0", + "_where": "/home/dold/repos/taler/wallet-webex/node_modules/nomnom", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "http://sindresorhus.com" + }, + "bugs": { + "url": "https://github.com/sindresorhus/chalk/issues" + }, + "dependencies": { + "ansi-styles": "~1.0.0", + "has-color": "~0.1.0", + "strip-ansi": "~0.1.0" + }, + "description": "Terminal string styling done right. Created because the `colors` module does some really horrible things.", + "devDependencies": { + "mocha": "~1.x" + }, + "directories": {}, + "dist": { + "shasum": "5199a3ddcd0c1efe23bc08c1b027b06176e0c64f", + "tarball": "https://registry.npmjs.org/chalk/-/chalk-0.4.0.tgz" + }, + "engines": { + "node": ">=0.8.0" + }, + "files": [ + "index.js" + ], + "homepage": "https://github.com/sindresorhus/chalk", + "keywords": [ + "color", + "colour", + "colors", + "terminal", + "console", + "cli", + "string", + "ansi", + "styles", + "tty", + "formatting", + "rgb", + "256", + "shell", + "xterm", + "log", + "logging", + "command-line", + "text" + ], + "license": "MIT", + "maintainers": [ + { + "name": "sindresorhus", + "email": "sindresorhus@gmail.com" + } + ], + "name": "chalk", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git://github.com/sindresorhus/chalk.git" + }, + "scripts": { + "test": "mocha" + }, + "version": "0.4.0" +} diff --git a/node_modules/nomnom/node_modules/chalk/readme.md b/node_modules/nomnom/node_modules/chalk/readme.md new file mode 100644 index 000000000..46813acfc --- /dev/null +++ b/node_modules/nomnom/node_modules/chalk/readme.md @@ -0,0 +1,158 @@ +# <img width="250" src="logo.png" alt="chalk"> + +> Terminal string styling done right + +[![Build Status](https://secure.travis-ci.org/sindresorhus/chalk.png?branch=master)](http://travis-ci.org/sindresorhus/chalk) + +[colors.js](https://github.com/Marak/colors.js) is currently the most popular string styling module, but it has serious deficiencies like extending String.prototype which causes all kinds of [problems](https://github.com/yeoman/yo/issues/68). Although there are other ones, they either do too much or not enough. + +**Chalk is a clean and focused alternative.** + +![screenshot](screenshot.png) + + +## Why + +- **Doesn't extend String.prototype** +- Expressive API +- Clean and focused +- Auto-detects color support +- Actively maintained +- [Used by 150+ modules](https://npmjs.org/browse/depended/chalk) + + +## Install + +Install with [npm](https://npmjs.org/package/chalk): `npm install --save chalk` + + +## Example + +Chalk comes with an easy to use composable API where you just chain and nest the styles you want. + +```js +var chalk = require('chalk'); + +// style a string +console.log( chalk.blue('Hello world!') ); + +// combine styled and normal strings +console.log( chalk.blue('Hello'), 'World' + chalk.red('!') ); + +// compose multiple styles using the chainable API +console.log( chalk.blue.bgRed.bold('Hello world!') ); + +// nest styles +console.log( chalk.red('Hello', chalk.underline.bgBlue('world') + '!') ); + +// pass in multiple arguments +console.log( chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz') ); +``` + +You can easily define your own themes. + +```js +var chalk = require('chalk'); +var error = chalk.bold.red; +console.log(error('Error!')); +``` + + +## API + +### chalk.`<style>[.<style>...](string, [string...])` + +Example: `chalk.red.bold.underline('Hello', 'world');` + +Chain [styles](#styles) and call the last one as a method with a string argument. Order doesn't matter. + +Multiple arguments will be separated by space. + +### chalk.enabled + +Color support is automatically detected, but you can override it. + +### chalk.supportsColor + +Detect whether the terminal [supports color](https://github.com/sindresorhus/has-color). + +Can be overridden by the user with the flags `--color` and `--no-color`. + +Used internally and handled for you, but exposed for convenience. + +### chalk.styles + +Exposes the styles as [ANSI escape codes](https://github.com/sindresorhus/ansi-styles). + +Generally not useful, but you might need just the `.open` or `.close` escape code if you're mixing externally styled strings with yours. + +```js +var chalk = require('chalk'); + +console.log(chalk.styles.red); +//=> {open: '\x1b[31m', close: '\x1b[39m'} + +console.log(chalk.styles.red.open + 'Hello' + chalk.styles.red.close); +``` + +### chalk.stripColor(string) + +[Strip color](https://github.com/sindresorhus/strip-ansi) from a string. + +Can be useful in combination with `.supportsColor` to strip color on externally styled text when it's not supported. + +Example: + +```js +var chalk = require('chalk'); +var styledString = fromExternal(); + +if (!chalk.supportsColor) { + chalk.stripColor(styledString); +} +``` + + +## Styles + +### General + +- reset +- bold +- italic +- underline +- inverse +- strikethrough + +### Text colors + +- black +- red +- green +- yellow +- blue +- magenta +- cyan +- white +- gray + +### Background colors + +- bgBlack +- bgRed +- bgGreen +- bgYellow +- bgBlue +- bgMagenta +- bgCyan +- bgWhite + + +## License + +MIT © [Sindre Sorhus](http://sindresorhus.com) + + +- + +[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/sindresorhus/chalk/trend.png)](https://bitdeli.com/free "Bitdeli Badge") diff --git a/node_modules/nomnom/node_modules/strip-ansi/cli.js b/node_modules/nomnom/node_modules/strip-ansi/cli.js new file mode 100755 index 000000000..f8019cdae --- /dev/null +++ b/node_modules/nomnom/node_modules/strip-ansi/cli.js @@ -0,0 +1,27 @@ +#!/usr/bin/env node +'use strict'; +var fs = require('fs'); +var strip = require('./index'); +var input = process.argv[2]; + +if (process.argv.indexOf('-h') !== -1 || process.argv.indexOf('--help') !== -1) { + console.log('strip-ansi <input file> > <output file>'); + console.log('or'); + console.log('cat <input file> | strip-ansi > <output file>'); + return; +} + +if (process.argv.indexOf('-v') !== -1 || process.argv.indexOf('--version') !== -1) { + console.log(require('./package').version); + return; +} + +if (input) { + process.stdout.write(strip(fs.readFileSync(input, 'utf8'))); + return; +} + +process.stdin.setEncoding('utf8'); +process.stdin.on('data', function (data) { + process.stdout.write(strip(data)); +}); diff --git a/node_modules/nomnom/node_modules/strip-ansi/index.js b/node_modules/nomnom/node_modules/strip-ansi/index.js new file mode 100644 index 000000000..62320c591 --- /dev/null +++ b/node_modules/nomnom/node_modules/strip-ansi/index.js @@ -0,0 +1,4 @@ +'use strict'; +module.exports = function (str) { + return typeof str === 'string' ? str.replace(/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]/g, '') : str; +}; diff --git a/node_modules/nomnom/node_modules/strip-ansi/package.json b/node_modules/nomnom/node_modules/strip-ansi/package.json new file mode 100644 index 000000000..11ba740b8 --- /dev/null +++ b/node_modules/nomnom/node_modules/strip-ansi/package.json @@ -0,0 +1,115 @@ +{ + "_args": [ + [ + { + "raw": "strip-ansi@~0.1.0", + "scope": null, + "escapedName": "strip-ansi", + "name": "strip-ansi", + "rawSpec": "~0.1.0", + "spec": ">=0.1.0 <0.2.0", + "type": "range" + }, + "/home/dold/repos/taler/wallet-webex/node_modules/nomnom/node_modules/chalk" + ] + ], + "_from": "strip-ansi@>=0.1.0 <0.2.0", + "_id": "strip-ansi@0.1.1", + "_inCache": true, + "_location": "/nomnom/strip-ansi", + "_npmUser": { + "name": "sindresorhus", + "email": "sindresorhus@gmail.com" + }, + "_npmVersion": "1.3.15", + "_phantomChildren": {}, + "_requested": { + "raw": "strip-ansi@~0.1.0", + "scope": null, + "escapedName": "strip-ansi", + "name": "strip-ansi", + "rawSpec": "~0.1.0", + "spec": ">=0.1.0 <0.2.0", + "type": "range" + }, + "_requiredBy": [ + "/nomnom/chalk" + ], + "_resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-0.1.1.tgz", + "_shasum": "39e8a98d044d150660abe4a6808acf70bb7bc991", + "_shrinkwrap": null, + "_spec": "strip-ansi@~0.1.0", + "_where": "/home/dold/repos/taler/wallet-webex/node_modules/nomnom/node_modules/chalk", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "http://sindresorhus.com" + }, + "bin": { + "strip-ansi": "cli.js" + }, + "bugs": { + "url": "https://github.com/sindresorhus/strip-ansi/issues" + }, + "dependencies": {}, + "description": "Strip ANSI escape codes (used for colorizing strings in the terminal)", + "devDependencies": { + "mocha": "~1.x" + }, + "directories": {}, + "dist": { + "shasum": "39e8a98d044d150660abe4a6808acf70bb7bc991", + "tarball": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-0.1.1.tgz" + }, + "engines": { + "node": ">=0.8.0" + }, + "files": [ + "index.js", + "cli.js" + ], + "homepage": "https://github.com/sindresorhus/strip-ansi", + "keywords": [ + "strip", + "trim", + "remove", + "ansi", + "styles", + "color", + "colour", + "colors", + "terminal", + "console", + "cli", + "string", + "tty", + "escape", + "formatting", + "rgb", + "256", + "shell", + "xterm", + "log", + "logging", + "command-line", + "text" + ], + "license": "MIT", + "maintainers": [ + { + "name": "sindresorhus", + "email": "sindresorhus@gmail.com" + } + ], + "name": "strip-ansi", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git://github.com/sindresorhus/strip-ansi.git" + }, + "scripts": { + "test": "mocha" + }, + "version": "0.1.1" +} diff --git a/node_modules/nomnom/node_modules/strip-ansi/readme.md b/node_modules/nomnom/node_modules/strip-ansi/readme.md new file mode 100644 index 000000000..eb661b3d8 --- /dev/null +++ b/node_modules/nomnom/node_modules/strip-ansi/readme.md @@ -0,0 +1,46 @@ +# strip-ansi [![Build Status](https://secure.travis-ci.org/sindresorhus/strip-ansi.png?branch=master)](http://travis-ci.org/sindresorhus/strip-ansi) + +> Strip [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles) (used for colorizing strings in the terminal) + +Used in the terminal color module [chalk](https://github.com/sindresorhus/chalk). + + +## Install + +Install locally with [npm](https://npmjs.org/package/strip-ansi): + +``` +npm install --save strip-ansi +``` + +Or globally if you want to use it as a CLI app: + +``` +npm install --global strip-ansi +``` + +You can then use it in your Terminal like: + +``` +strip-ansi file-with-color-codes +``` + +Or pipe something to it: + +``` +ls | strip-ansi +``` + + +## Example + +```js +var stripAnsi = require('strip-ansi'); +stripAnsi('\x1b[4mcake\x1b[0m'); +//=> cake +``` + + +## License + +MIT © [Sindre Sorhus](http://sindresorhus.com) diff --git a/node_modules/nomnom/nomnom.js b/node_modules/nomnom/nomnom.js new file mode 100644 index 000000000..315597414 --- /dev/null +++ b/node_modules/nomnom/nomnom.js @@ -0,0 +1,584 @@ +var _ = require("underscore"), chalk = require('chalk'); + + +function ArgParser() { + this.commands = {}; // expected commands + this.specs = {}; // option specifications +} + +ArgParser.prototype = { + /* Add a command to the expected commands */ + command : function(name) { + var command; + if (name) { + command = this.commands[name] = { + name: name, + specs: {} + }; + } + else { + command = this.fallback = { + specs: {} + }; + } + + // facilitates command('name').options().cb().help() + var chain = { + options : function(specs) { + command.specs = specs; + return chain; + }, + opts : function(specs) { + // old API + return this.options(specs); + }, + option : function(name, spec) { + command.specs[name] = spec; + return chain; + }, + callback : function(cb) { + command.cb = cb; + return chain; + }, + help : function(help) { + command.help = help; + return chain; + }, + usage : function(usage) { + command._usage = usage; + return chain; + } + }; + return chain; + }, + + nocommand : function() { + return this.command(); + }, + + options : function(specs) { + this.specs = specs; + return this; + }, + + opts : function(specs) { + // old API + return this.options(specs); + }, + + globalOpts : function(specs) { + // old API + return this.options(specs); + }, + + option : function(name, spec) { + this.specs[name] = spec; + return this; + }, + + usage : function(usage) { + this._usage = usage; + return this; + }, + + printer : function(print) { + this.print = print; + return this; + }, + + script : function(script) { + this._script = script; + return this; + }, + + scriptName : function(script) { + // old API + return this.script(script); + }, + + help : function(help) { + this._help = help; + return this; + }, + + colors: function() { + // deprecated - colors are on by default now + return this; + }, + + nocolors : function() { + this._nocolors = true; + return this; + }, + + parseArgs : function(argv) { + // old API + return this.parse(argv); + }, + + nom : function(argv) { + return this.parse(argv); + }, + + parse : function(argv) { + this.print = this.print || function(str, code) { + console.log(str); + process.exit(code || 0); + }; + this._help = this._help || ""; + this._script = this._script || process.argv[0] + " " + + require('path').basename(process.argv[1]); + this.specs = this.specs || {}; + + var argv = argv || process.argv.slice(2); + + var arg = Arg(argv[0]).isValue && argv[0], + command = arg && this.commands[arg], + commandExpected = !_(this.commands).isEmpty(); + + if (commandExpected) { + if (command) { + _(this.specs).extend(command.specs); + this._script += " " + command.name; + if (command.help) { + this._help = command.help; + } + this.command = command; + } + else if (arg) { + return this.print(this._script + ": no such command '" + arg + "'", 1); + } + else { + // no command but command expected e.g. 'git -v' + var helpStringBuilder = { + list : function() { + return 'one of: ' + _(this.commands).keys().join(", "); + }, + twoColumn : function() { + // find the longest command name to ensure horizontal alignment + var maxLength = _(this.commands).max(function (cmd) { + return cmd.name.length; + }).name.length; + + // create the two column text strings + var cmdHelp = _.map(this.commands, function(cmd, name) { + var diff = maxLength - name.length; + var pad = new Array(diff + 4).join(" "); + return " " + [ name, pad, cmd.help ].join(" "); + }); + return "\n" + cmdHelp.join("\n"); + } + }; + + // if there are a small number of commands and all have help strings, + // display them in a two column table; otherwise use the brief version. + // The arbitrary choice of "20" comes from the number commands git + // displays as "common commands" + var helpType = 'list'; + if (_(this.commands).size() <= 20) { + if (_(this.commands).every(function (cmd) { return cmd.help; })) { + helpType = 'twoColumn'; + } + } + + this.specs.command = { + position: 0, + help: helpStringBuilder[helpType].call(this) + } + + if (this.fallback) { + _(this.specs).extend(this.fallback.specs); + this._help = this.fallback.help; + } else { + this.specs.command.required = true; + } + } + } + + if (this.specs.length === undefined) { + // specs is a hash not an array + this.specs = _(this.specs).map(function(opt, name) { + opt.name = name; + return opt; + }); + } + this.specs = this.specs.map(function(opt) { + return Opt(opt); + }); + + if (argv.indexOf("--help") >= 0 || argv.indexOf("-h") >= 0) { + return this.print(this.getUsage()); + } + + var options = {}; + var args = argv.map(function(arg) { + return Arg(arg); + }) + .concat(Arg()); + + var positionals = []; + + /* parse the args */ + var that = this; + args.reduce(function(arg, val) { + /* positional */ + if (arg.isValue) { + positionals.push(arg.value); + } + else if (arg.chars) { + var last = arg.chars.pop(); + + /* -cfv */ + (arg.chars).forEach(function(ch) { + that.setOption(options, ch, true); + }); + + /* -v key */ + if (!that.opt(last).flag) { + if (val.isValue) { + that.setOption(options, last, val.value); + return Arg(); // skip next turn - swallow arg + } + else { + that.print("'-" + (that.opt(last).name || last) + "'" + + " expects a value\n\n" + that.getUsage(), 1); + } + } + else { + /* -v */ + that.setOption(options, last, true); + } + + } + else if (arg.full) { + var value = arg.value; + + /* --key */ + if (value === undefined) { + /* --key value */ + if (!that.opt(arg.full).flag) { + if (val.isValue) { + that.setOption(options, arg.full, val.value); + return Arg(); + } + else { + that.print("'--" + (that.opt(arg.full).name || arg.full) + "'" + + " expects a value\n\n" + that.getUsage(), 1); + } + } + else { + /* --flag */ + value = true; + } + } + that.setOption(options, arg.full, value); + } + return val; + }); + + positionals.forEach(function(pos, index) { + this.setOption(options, index, pos); + }, this); + + options._ = positionals; + + this.specs.forEach(function(opt) { + if (opt.default !== undefined && options[opt.name] === undefined) { + options[opt.name] = opt.default; + } + }, this); + + // exit if required arg isn't present + this.specs.forEach(function(opt) { + if (opt.required && options[opt.name] === undefined) { + var msg = opt.name + " argument is required"; + msg = this._nocolors ? msg : chalk.red(msg); + + this.print("\n" + msg + "\n" + this.getUsage(), 1); + } + }, this); + + if (command && command.cb) { + command.cb(options); + } + else if (this.fallback && this.fallback.cb) { + this.fallback.cb(options); + } + + return options; + }, + + getUsage : function() { + if (this.command && this.command._usage) { + return this.command._usage; + } + else if (this.fallback && this.fallback._usage) { + return this.fallback._usage; + } + if (this._usage) { + return this._usage; + } + + // todo: use a template + var str = "\n" + if (!this._nocolors) { + str += chalk.bold("Usage:"); + } + else { + str += "Usage:"; + } + str += " " + this._script; + + var positionals = _(this.specs).select(function(opt) { + return opt.position != undefined; + }) + positionals = _(positionals).sortBy(function(opt) { + return opt.position; + }); + var options = _(this.specs).select(function(opt) { + return opt.position === undefined; + }); + + // assume there are no gaps in the specified pos. args + positionals.forEach(function(pos) { + str += " "; + var posStr = pos.string; + if (!posStr) { + posStr = pos.name || "arg" + pos.position; + if (pos.required) { + posStr = "<" + posStr + ">"; + } else { + posStr = "[" + posStr + "]"; + } + if (pos.list) { + posStr += "..."; + } + } + str += posStr; + }); + + if (options.length) { + if (!this._nocolors) { + // must be a better way to do this + str += chalk.blue(" [options]"); + } + else { + str += " [options]"; + } + } + + if (options.length || positionals.length) { + str += "\n\n"; + } + + function spaces(length) { + var spaces = ""; + for (var i = 0; i < length; i++) { + spaces += " "; + } + return spaces; + } + var longest = positionals.reduce(function(max, pos) { + return pos.name.length > max ? pos.name.length : max; + }, 0); + + positionals.forEach(function(pos) { + var posStr = pos.string || pos.name; + str += posStr + spaces(longest - posStr.length) + " "; + if (!this._nocolors) { + str += chalk.grey(pos.help || "") + } + else { + str += (pos.help || "") + } + str += "\n"; + }, this); + if (positionals.length && options.length) { + str += "\n"; + } + + if (options.length) { + if (!this._nocolors) { + str += chalk.blue("Options:"); + } + else { + str += "Options:"; + } + str += "\n" + + var longest = options.reduce(function(max, opt) { + return opt.string.length > max && !opt.hidden ? opt.string.length : max; + }, 0); + + options.forEach(function(opt) { + if (!opt.hidden) { + str += " " + opt.string + spaces(longest - opt.string.length) + " "; + + var defaults = (opt.default != null ? " [" + opt.default + "]" : ""); + var help = opt.help ? opt.help + defaults : ""; + str += this._nocolors ? help: chalk.grey(help); + + str += "\n"; + } + }, this); + } + + if (this._help) { + str += "\n" + this._help; + } + return str; + } +}; + +ArgParser.prototype.opt = function(arg) { + // get the specified opt for this parsed arg + var match = Opt({}); + this.specs.forEach(function(opt) { + if (opt.matches(arg)) { + match = opt; + } + }); + return match; +}; + +ArgParser.prototype.setOption = function(options, arg, value) { + var option = this.opt(arg); + if (option.callback) { + var message = option.callback(value); + + if (typeof message == "string") { + this.print(message, 1); + } + } + + if (option.type != "string") { + try { + // infer type by JSON parsing the string + value = JSON.parse(value) + } + catch(e) {} + } + + if (option.transform) { + value = option.transform(value); + } + + var name = option.name || arg; + if (option.choices && option.choices.indexOf(value) == -1) { + this.print(name + " must be one of: " + option.choices.join(", "), 1); + } + + if (option.list) { + if (!options[name]) { + options[name] = [value]; + } + else { + options[name].push(value); + } + } + else { + options[name] = value; + } +}; + + +/* an arg is an item that's actually parsed from the command line + e.g. "-l", "log.txt", or "--logfile=log.txt" */ +var Arg = function(str) { + var abbrRegex = /^\-(\w+?)$/, + fullRegex = /^\-\-(no\-)?(.+?)(?:=(.+))?$/, + valRegex = /^[^\-].*/; + + var charMatch = abbrRegex.exec(str), + chars = charMatch && charMatch[1].split(""); + + var fullMatch = fullRegex.exec(str), + full = fullMatch && fullMatch[2]; + + var isValue = str !== undefined && (str === "" || valRegex.test(str)); + var value; + if (isValue) { + value = str; + } + else if (full) { + value = fullMatch[1] ? false : fullMatch[3]; + } + + return { + str: str, + chars: chars, + full: full, + value: value, + isValue: isValue + } +} + + +/* an opt is what's specified by the user in opts hash */ +var Opt = function(opt) { + var strings = (opt.string || "").split(","), + abbr, full, metavar; + for (var i = 0; i < strings.length; i++) { + var string = strings[i].trim(), + matches; + if (matches = string.match(/^\-([^-])(?:\s+(.*))?$/)) { + abbr = matches[1]; + metavar = matches[2]; + } + else if (matches = string.match(/^\-\-(.+?)(?:[=\s]+(.+))?$/)) { + full = matches[1]; + metavar = metavar || matches[2]; + } + } + + matches = matches || []; + var abbr = opt.abbr || abbr, // e.g. v from -v + full = opt.full || full, // e.g. verbose from --verbose + metavar = opt.metavar || metavar; // e.g. PATH from '--config=PATH' + + var string; + if (opt.string) { + string = opt.string; + } + else if (opt.position === undefined) { + string = ""; + if (abbr) { + string += "-" + abbr; + if (metavar) + string += " " + metavar + string += ", "; + } + string += "--" + (full || opt.name); + if (metavar) { + string += " " + metavar; + } + } + + opt = _(opt).extend({ + name: opt.name || full || abbr, + string: string, + abbr: abbr, + full: full, + metavar: metavar, + matches: function(arg) { + return opt.full == arg || opt.abbr == arg || opt.position == arg + || opt.name == arg || (opt.list && arg >= opt.position); + } + }); + return opt; +} + + +var createParser = function() { + return new ArgParser(); +} + +var nomnom = createParser(); + +for (var i in nomnom) { + if (typeof nomnom[i] == "function") { + createParser[i] = _(nomnom[i]).bind(nomnom); + } +} + +module.exports = createParser; diff --git a/node_modules/nomnom/num-vals-fix.diff b/node_modules/nomnom/num-vals-fix.diff new file mode 100644 index 000000000..3c4f16791 --- /dev/null +++ b/node_modules/nomnom/num-vals-fix.diff @@ -0,0 +1,31 @@ +diff --git a/test/values.js b/test/values.js +index efad789..7fa1078 100644 +--- a/test/values.js ++++ b/test/values.js +@@ -26,6 +26,12 @@ var opts = { + }, + def2: { + default: "val1" ++ }, ++ "2d": { ++ flag: true ++ }, ++ "3d": { ++ abbr: "3" + } + } + +@@ -80,8 +86,12 @@ exports.testDash = function(test) { + }; + + exports.testNumbers = function(test) { +- var options = parser.parseArgs(['sum', '-1', '2.5', '-3.5', '4']); ++ var options = parser.parseArgs(['sum', '-1', '2.5', '-3.5', '4', '--2d', '-3', 'test']); + + test.deepEqual(options.list3, ['-1', '2.5', '-3.5', '4']); ++ test.strictEqual(options['2d'], true); ++ test.strictEqual(options['3d'], "test") + test.done(); + }; ++ ++ diff --git a/node_modules/nomnom/package.json b/node_modules/nomnom/package.json new file mode 100644 index 000000000..6c9f8b16f --- /dev/null +++ b/node_modules/nomnom/package.json @@ -0,0 +1,91 @@ +{ + "_args": [ + [ + { + "raw": "nomnom@1.8.1", + "scope": null, + "escapedName": "nomnom", + "name": "nomnom", + "rawSpec": "1.8.1", + "spec": "1.8.1", + "type": "version" + }, + "/home/dold/repos/taler/wallet-webex/node_modules/po2json" + ] + ], + "_from": "nomnom@1.8.1", + "_id": "nomnom@1.8.1", + "_inCache": true, + "_location": "/nomnom", + "_npmUser": { + "name": "harth", + "email": "fayearthur@gmail.com" + }, + "_npmVersion": "1.4.3", + "_phantomChildren": { + "has-color": "0.1.7" + }, + "_requested": { + "raw": "nomnom@1.8.1", + "scope": null, + "escapedName": "nomnom", + "name": "nomnom", + "rawSpec": "1.8.1", + "spec": "1.8.1", + "type": "version" + }, + "_requiredBy": [ + "/po2json" + ], + "_resolved": "https://registry.npmjs.org/nomnom/-/nomnom-1.8.1.tgz", + "_shasum": "2151f722472ba79e50a76fc125bb8c8f2e4dc2a7", + "_shrinkwrap": null, + "_spec": "nomnom@1.8.1", + "_where": "/home/dold/repos/taler/wallet-webex/node_modules/po2json", + "author": { + "name": "Heather Arthur", + "email": "fayearthur@gmail.com" + }, + "bugs": { + "url": "https://github.com/harthur/nomnom/issues" + }, + "dependencies": { + "chalk": "~0.4.0", + "underscore": "~1.6.0" + }, + "description": "Option parser with generated usage and commands", + "devDependencies": { + "nodeunit": "~0.7.4" + }, + "directories": {}, + "dist": { + "shasum": "2151f722472ba79e50a76fc125bb8c8f2e4dc2a7", + "tarball": "https://registry.npmjs.org/nomnom/-/nomnom-1.8.1.tgz" + }, + "homepage": "https://github.com/harthur/nomnom", + "keywords": [ + "arguments", + "option parser", + "command line", + "options", + "parser" + ], + "main": "./nomnom", + "maintainers": [ + { + "name": "harth", + "email": "fayearthur@gmail.com" + } + ], + "name": "nomnom", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git+ssh://git@github.com/harthur/nomnom.git" + }, + "scripts": { + "test": "nodeunit test/*.js" + }, + "version": "1.8.1" +} diff --git a/node_modules/nomnom/test.js b/node_modules/nomnom/test.js new file mode 100644 index 000000000..db99a1e94 --- /dev/null +++ b/node_modules/nomnom/test.js @@ -0,0 +1,23 @@ +var opts = require("./nomnom") + .option('debug', { + abbr: 'd', + flag: true, + help: 'Print debugging info' + }) + .option('config', { + abbr: 'c', + default: 'config.json', + help: 'JSON file with tests to run' + }) + .option('version', { + flag: true, + help: 'print version and exit', + callback: function() { + return "version 1.2.4"; + } + }) + .parse(); + +if (opts.debug) { + console.log("debug") +} diff --git a/node_modules/nomnom/test/callback.js b/node_modules/nomnom/test/callback.js new file mode 100644 index 000000000..3d512dbed --- /dev/null +++ b/node_modules/nomnom/test/callback.js @@ -0,0 +1,33 @@ +var nomnom = require("../nomnom"); + +exports.testVersion = function(test) { + test.expect(1); + + nomnom().options({ + date: { + callback: function(date) { + test.equal(date, "2010-02-03", "date should match value") + } + } + }).parse(["--date=2010-02-03"]); + + test.done(); +} + +exports.testReturnString = function(test) { + test.expect(1); + + nomnom().options({ + version: { + flag: true, + callback: function() { + return "v0.3"; + } + } + }) + .printer(function(string) { + test.equal(0, string.indexOf("v0.3")) + test.done(); + }) + .parse(["--version"]); +}
\ No newline at end of file diff --git a/node_modules/nomnom/test/commands.js b/node_modules/nomnom/test/commands.js new file mode 100644 index 000000000..1fbb60f6a --- /dev/null +++ b/node_modules/nomnom/test/commands.js @@ -0,0 +1,120 @@ +var nomnom = require("../nomnom"); + +function strip(str) { + return str.replace(/\s+/g, ''); +} + +exports.testCallback = function(test) { + test.expect(1); + + var parser = nomnom(); + parser.command('run').callback(function(options) { + test.equal(options.v, 3); + }); + parser.command('other').callback(function() { + test.ok(false, "callback for other command shouldn't be called"); + }); + + parser.parse(["run","-v", "3"]); + test.done(); +} + +exports.testMissingCommand = function(test) { + test.expect(1); + + var parser = nomnom().scriptName("test"); + + parser.command('run'); + + parser.printer(function(string) { + test.equal(string, "test: no such command 'other'"); + test.done(); + }); + + parser.parse(["other"]); +} + +exports.testNoCommand = function(test) { + test.expect(2); + + var parser = nomnom(); + + parser.nocommand() + .options({ + version: { + flag: true + } + }) + .callback(function(options) { + test.strictEqual(options.version, true); + }) + .usage("fallback usage"); + + parser.command('run'); + + var options = parser.parse(["--version"]); + + test.strictEqual(options.version, true); + test.done(); +} + +function createParser() { + var parser = nomnom().scriptName("test") + .options({ + debug: { + flag: true + } + }); + + parser.command('run') + .options({ + file: { + help: 'file to run' + } + }) + .help("run all"); + + parser.command('test').usage("test usage"); + + parser.nocommand() + .options({ + verbose: { + flag: true + } + }) + .help("nocommand"); + + return parser; +} + +exports.testUsage = function(test) { + test.expect(4); + + var parser = createParser(); + parser.printer(function(string) { + test.equal(strip(string), "testusage"); + }); + parser.parse(["test", "-h"]); + + parser = createParser().nocolors(); + parser.printer(function(string) { + test.equal(strip(string), "Usage:testrun[options]Options:--debug--filefiletorunrunall"); + }); + parser.parse(["run", "-h"]); + + parser = createParser().nocolors(); + parser.printer(function(string) { + test.equal(strip(string), "Usage:test[command][options]commandoneof:run,testOptions:--debug--verbosenocommand"); + }); + parser.parse(["-h"]); + + parser = createParser().nocolors(); + parser.nocommand() + .usage("fallback"); + parser.printer(function(string) { + test.equal(strip(string), "fallback"); + }); + parser.parse(["-h"]); + + test.done(); +} diff --git a/node_modules/nomnom/test/expected.js b/node_modules/nomnom/test/expected.js new file mode 100644 index 000000000..f52bd57de --- /dev/null +++ b/node_modules/nomnom/test/expected.js @@ -0,0 +1,60 @@ +var nomnom = require("../nomnom"); + +var opts = { + file: { + position: 0, + required: true + } +} + +var parser = nomnom().options(opts); + +exports.testFlag = function(test) { + test.expect(1); + + nomnom().options({ + file: { + position: 0, + } + }) + .printer(function(string) { + test.equal(0, string.indexOf("'--key1' expects a value")) + test.done(); + }) + .parse(["--key1"]); +} + +exports.testRequired = function(test) { + test.expect(1); + + nomnom().options({ + file: { + required: true + } + }) + .printer(function(string) { + test.equal(0, string.trim().indexOf("file argument is required")) + test.done(); + }) + .nocolors() + .parse([]); +} + +exports.testChoices = function(test) { + test.expect(2); + + var parser = nomnom().options({ + color: { + choices: ['green', 'blue'] + } + }) + .printer(function(string) { + test.equal(0, string.indexOf("color must be one of: green, blue")) + }); + + parser.parse(['--color', 'red']); + + var options = parser.parse(['--color', 'green']); + test.equal(options.color, 'green'); + test.done(); +} diff --git a/node_modules/nomnom/test/matching.js b/node_modules/nomnom/test/matching.js new file mode 100644 index 000000000..8d347eb0f --- /dev/null +++ b/node_modules/nomnom/test/matching.js @@ -0,0 +1,70 @@ +var nomnom = require("../nomnom"); + +var opts = { + pos1: { + position: 0 + }, + pos2: { + position: 1 + }, + flag1: { + flag: true + }, + debug: { + abbr: 'd' + }, + numLines: { + abbr: 'n', + full: 'num-lines' + }, + version: { + string: '-v, --version' + }, + config: { + string: '-c FILE, --config=FILE' + }, + skey : { + string: '-k val' + }, + skey2: { + string: '-k2 val2, --key2 val2' + }, + skey3: { + string: '--key3=val' + }, + skey4: { + string: '--key4=val, -y val' + } +} + +var parser = nomnom().options(opts); + +exports.testPositional = function(test) { + var options = parser.parse(["--flag1", "val1", "--config", "file", "val2"]); + + test.equal(options.pos1, "val1"); + test.equal(options.pos2, "val2"); + test.deepEqual(options._, ["val1", "val2"]) + test.done(); +} + +exports.testAbbr = function(test) { + var options = parser.parse(["-d", "yes", "--num-lines", "3"]); + + test.equal(options.debug, "yes") + test.equal(options.numLines, 3) + test.done(); +} + +exports.testString = function(test) { + var options = parser.parse(["-k", "val", "--config=test.js", + "--key2", "val2", "--key3", "val3", "--key4=val4", "-v", "v0.3"]); + + test.equal(options.version, "v0.3") + test.equal(options.config, "test.js") + test.equal(options.skey, "val") + test.equal(options.skey2, "val2") + test.equal(options.skey3, "val3") + test.equal(options.skey4, "val4") + test.done(); +} diff --git a/node_modules/nomnom/test/option.js b/node_modules/nomnom/test/option.js new file mode 100644 index 000000000..e3934d75e --- /dev/null +++ b/node_modules/nomnom/test/option.js @@ -0,0 +1,44 @@ +var nomnom = require("../nomnom"); + +var parser = nomnom() + .option('debug', { + abbr: 'x', + flag: true, + help: 'Print debugging info' + }) + .option('config', { + abbr: 'c', + default: 'config.json', + help: 'JSON file with tests to run' + }) + .option('version', { + flag: true, + help: 'print version and exit', + callback: function() { + return "version 1.2.4"; + } + }); + + +exports.testOption = function(test) { + var opts = parser.parse(["-x", "--no-verbose"]); + + test.strictEqual(opts.debug, true); + test.equal(opts.config, "config.json"); + test.done(); +} + + +exports.testCommandOption = function(test) { + var parser = nomnom() + parser.command('test') + .option('fruit', { + abbr: 'f', + flag: true + }) + + var opts = parser.parse(["test", "-f"]); + + test.strictEqual(opts.fruit, true); + test.done(); +} diff --git a/node_modules/nomnom/test/transform.js b/node_modules/nomnom/test/transform.js new file mode 100644 index 000000000..666a6a233 --- /dev/null +++ b/node_modules/nomnom/test/transform.js @@ -0,0 +1,65 @@ +var nomnom = require("../nomnom"); + +var parser = nomnom() + .option("addr", { + abbr: "a", + help: "host:port address", + transform: function(value) { + var parts = value.split(":"); + return {host: parts[0], port: Number(parts[1])}; + } + }) + .option("string", { + abbr: "s", + help: "always a string", + transform: function(value) { + return value.toString(); + } + }); + + +exports.testTransformComplexValue = function(test) { + var opts = parser.parse(["-a", "localhost:1234"]); + + test.strictEqual(opts.addr.host, "localhost"); + test.strictEqual(opts.addr.port, 1234); + test.done(); +}; + + +exports.testTransformString = function(test) { + var opts = parser.parse(["-s", "3"]); + + test.strictEqual(opts.string, "3"); + test.done(); +}; + + +exports.testTransformCommand = function(test) { + test.expect(1); + + var parser = nomnom().scriptName("test") + .options({ + addr: { + transform: function(value) { + var parts = value.split(":"); + return {host: parts[0], port: Number(parts[1])}; + } + } + }); + + parser.command("run") + .options({ + string: { + transform: function(value) { + return value.toString(); + } + } + }) + .callback(function(options) { + test.strictEqual(options.string, "true"); + }); + + parser.parse(["run", "--string=true"]); + test.done(); +}; diff --git a/node_modules/nomnom/test/usage.js b/node_modules/nomnom/test/usage.js new file mode 100644 index 000000000..9a0817935 --- /dev/null +++ b/node_modules/nomnom/test/usage.js @@ -0,0 +1,121 @@ +var nomnom = require("../nomnom"); + +function strip(str) { + return str.replace(/\s+/g, ''); +}; + +var opts = { + apple: { + abbr: 'a', + help: 'how many apples' + }, + + banana: { + full: "b-nana" + }, + + carrot: { + string: '-c NUM, --carrots=NUM' + }, + + dill: { + metavar: 'PICKLE' + }, + + egg: { + position: 0, + help: 'robin' + } +} + +var parser = nomnom().options(opts).help("all the best foods").scriptName("test").nocolors(); + +var expected = "Usage:test[egg][options]eggrobinOptions:-a,--applehowmanyapples--b-nana-cNUM,--carrots=NUM--dillPICKLEallthebestfoods" + +exports.testH = function(test) { + test.expect(1); + + parser.printer(function(string) { + test.equal(strip(string), expected) + test.done(); + }) + .nocolors() + .parse(["-h"]); +} + +exports.testHelp = function(test) { + test.expect(1); + + parser.printer(function(string) { + test.equal(strip(string), expected) + test.done(); + }) + .nocolors() + .parse(["--help"]); +} + +exports.testScriptName = function(test) { + test.expect(1); + + nomnom() + .script("test") + .printer(function(string) { + test.equal(strip(string),"Usage:test") + test.done(); + }) + .nocolors() + .parse(["-h"]); +} + +exports.testUsage = function(test) { + test.expect(1); + + parser + .usage("test usage") + .printer(function(string) { + test.equal(string, "test usage") + test.done(); + }) + .nocolors() + .parse(["--help"]); +} + +exports.testHidden = function(test) { + test.expect(1); + + nomnom().options({ + file: { + hidden: true + } + }) + .scriptName("test") + .printer(function(string) { + test.equal(strip("Usage:test[options]Options:"), strip(string)) + test.done(); + }) + .nocolors() + .parse(["-h"]); +} + +exports.testRequiredOptional = function(test) { + test.expect(1); + + nomnom().options({ + foo: { + position: 0, + required: true, + help: 'The foo' + }, + bar: { + position: 1, + help: 'The bar' + } + }) + .scriptName("test") + .printer(function(string) { + test.equal(strip("Usage:test<foo>[bar]fooThefoobarThebar"), strip(string)) + test.done(); + }) + .nocolors() + .parse(["-h"]); +} diff --git a/node_modules/nomnom/test/values.js b/node_modules/nomnom/test/values.js new file mode 100644 index 000000000..797807e5e --- /dev/null +++ b/node_modules/nomnom/test/values.js @@ -0,0 +1,75 @@ +var nomnom = require("../nomnom"); + +var opts = { + debug: { + flag: true + }, + verbose: { + flag: true, + default: true + }, + list1: { + list: true + }, + list2: { + list: true + }, + list3: { + position: 1, + list: true + }, + num1: { + type: "string" + }, + def1: { + default: "val1" + }, + def2: { + default: "val1" + } +} + +var parser = nomnom().options(opts); + +exports.testFlag = function(test) { + var options = parser.parse(["--debug", "pos0", "--no-verbose"]); + + test.strictEqual(options.debug, true); + test.strictEqual(options.verbose, false); + test.equal(options[0], "pos0"); + test.equal(options._[0], "pos0"); + test.done(); +} + +exports.testList = function(test) { + var options = parser.parse(["pos0", "pos1", "--list1=val0", "--list2", "val1", + "--list2", "val2", "pos2"]); + + test.deepEqual(options.list1, ["val0"]); + test.deepEqual(options.list2, ["val1", "val2"]); + test.deepEqual(options.list3, ["pos1", "pos2"]); + test.done(); +} + +exports.testDefault = function(test) { + var options = parser.parse(["--def2", "val2", "--def3", "val3"]); + + test.strictEqual(options.def1, "val1"); + test.strictEqual(options.def2, "val2"); + test.strictEqual(options.def3, "val3"); + test.done(); +} + +exports.testTypes = function(test) { + var options = parser.parseArgs(["", "-x", "3.14", "-w", "true", "-q", "120", + "--num1", "4"]); + + test.strictEqual(options[0], ""); + test.strictEqual(options.x, 3.14); + test.strictEqual(options.w, true); + test.strictEqual(options.q, 120); + test.strictEqual(options.num1, "4"); + test.done(); +} + + |