Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

remove node_modules from git project

  • Loading branch information...
commit 4e619f801059650a6fac5c6cb6cf708b56d1664a 1 parent bda6231
Dylan Greene authored

Showing 45 changed files with 0 additions and 3,555 deletions. Show diff stats Hide diff stats

  1. +0 196 node_modules/cli/README.md
  2. +0 1,125 node_modules/cli/cli.js
  3. +0 17 node_modules/cli/examples/cat.js
  4. +0 16 node_modules/cli/examples/command.js
  5. +0 54 node_modules/cli/examples/echo.js
  6. +0 6 node_modules/cli/examples/glob.js
  7. +0 20 node_modules/cli/examples/long_desc.js
  8. +0 11 node_modules/cli/examples/progress.js
  9. +0 18 node_modules/cli/examples/sort.js
  10. +0 9 node_modules/cli/examples/spinner.js
  11. +0 27 node_modules/cli/examples/static.coffee
  12. +0 25 node_modules/cli/examples/static.js
  13. +0 1  node_modules/cli/index.js
  14. +0 23 node_modules/cli/package.json
  15. +0 55 node_modules/request/LICENSE
  16. +0 123 node_modules/request/README.md
  17. +0 150 node_modules/request/cookies.js
  18. +0 424 node_modules/request/main.js
  19. +0 146 node_modules/request/mimetypes.js
  20. +0 14 node_modules/request/package.json
  21. BIN  node_modules/request/tests/googledoodle.png
  22. +0 45 node_modules/request/tests/server.js
  23. +0 74 node_modules/request/tests/test-body.js
  24. 0  node_modules/request/tests/test-cookies.js
  25. +0 30 node_modules/request/tests/test-errors.js
  26. +0 136 node_modules/request/tests/test-pipes.js
  27. +0 7 node_modules/request/tests/test-ssl.js
  28. +0 84 node_modules/request/tests/test-timeout.js
  29. +0 71 node_modules/step/README.markdown
  30. +0 154 node_modules/step/lib/step.js
  31. +0 11 node_modules/step/package.json
  32. +0 26 node_modules/step/test/callbackTest.js
  33. +0 27 node_modules/step/test/errorTest.js
  34. +0 21 node_modules/step/test/fnTest.js
  35. +0 102 node_modules/step/test/groupTest.js
  36. +0 17 node_modules/step/test/helper.js
  37. +0 49 node_modules/step/test/parallelTest.js
  38. +0 1  node_modules/wordwrap/.npmignore
  39. +0 54 node_modules/wordwrap/README.markdown
  40. +0 10 node_modules/wordwrap/example/center.js
  41. +0 3  node_modules/wordwrap/example/meat.js
  42. +0 42 node_modules/wordwrap/index.js
  43. +0 37 node_modules/wordwrap/package.json
  44. +0 63 node_modules/wordwrap/test/idleness.txt
  45. +0 31 node_modules/wordwrap/test/wrap.js
196 node_modules/cli/README.md
Source Rendered
... ... @@ -1,196 +0,0 @@
1   -**cli is a toolkit for rapidly building command line apps - it includes:**
2   -
3   -- Full featured opts/args parser
4   -- Plugin support for adding common options and switches
5   -- Helper methods for working with input/output and spawning child processes
6   -- Output colored/styled messages, [progress bars](https://github.com/chriso/cli/blob/master/examples/progress.js) or [spinners](https://github.com/chriso/cli/blob/master/examples/spinner.js)
7   -- Command [auto-completion](https://github.com/chriso/cli/blob/master/examples/command.js) and [glob support](https://github.com/chriso/cli/blob/master/examples/glob.js)
8   -
9   -Install using `npm install cli` or just bundle [cli.js](https://github.com/chriso/cli/raw/master/cli-min.js) with your app.
10   -
11   -## Example apps
12   -
13   -### sort.js
14   -
15   -```javascript
16   -#!/usr/bin/env node
17   -require('cli').withStdinLines(function(lines, newline) {
18   - this.output(lines.sort().join(newline));
19   -});
20   -```
21   -
22   -Try it out
23   -
24   -```bash
25   -$ ./sort.js < input.txt
26   -```
27   -
28   -Let's add support for an `-n` switch to use a numeric sort, and a `-r` switch to reverse output - only 5 extra lines of code (!)
29   -
30   -```javascript
31   -var cli = require('cli'), options = cli.parse();
32   -
33   -cli.withStdinLines(function(lines, newline) {
34   - lines.sort(!options.n ? null : function(a, b) {
35   - return parseInt(a) > parseInt(b);
36   - });
37   - if (options.r) lines.reverse();
38   - this.output(lines.join(newline));
39   -});
40   -```
41   -
42   -### static.js
43   -
44   -Let's create a static file server with daemon support to see the opts parser + plugins in use - note: this requires `npm install creationix daemon`
45   -
46   -```javascript
47   -var cli = require('cli').enable('daemon', 'status'); //Enable 2 plugins
48   -
49   -cli.parse({
50   - log: ['l', 'Enable logging'],
51   - port: ['p', 'Listen on this port', 'number', 8080],
52   - serve: [false, 'Serve static files from PATH', 'path', './public']
53   -});
54   -
55   -cli.main(function(args, options) {
56   - var server, middleware = [];
57   -
58   - if (options.log) {
59   - this.debug('Enabling logging');
60   - middleware.push(require('creationix/log')());
61   - }
62   -
63   - this.debug('Serving files from ' + options.serve);
64   - middleware.push(require('creationix/static')('/', options.serve, 'index.html'));
65   -
66   - server = this.createServer(middleware).listen(options.port);
67   -
68   - this.ok('Listening on port ' + options.port);
69   -});
70   -```
71   -
72   -To output usage information
73   -
74   -```bash
75   -$ ./static.js --help
76   -```
77   -
78   -To create a daemon that serves files from */tmp*, run
79   -
80   -```bash
81   -$ ./static.js -ld --serve=/tmp
82   -```
83   -
84   -For more examples, see [./examples](https://github.com/chriso/cli/tree/master/examples)
85   -
86   -## Helper methods
87   -
88   -cli has methods that collect stdin (newline is autodetected as \n or \r\n)
89   -
90   -```javascript
91   -cli.withStdin(callback); //callback receives stdin as a string
92   -cli.withStdinLines(callback); //callback receives stdin split into an array of lines (lines, newline)
93   -```
94   -
95   -cli also has a lower level method for working with input line by line (see [./examples/cat.js](https://github.com/chriso/cli/blob/master/examples/cat.js) for an example).
96   -
97   -```javascript
98   -cli.withInput(file, function (line, newline, eof) {
99   - if (!eof) {
100   - this.output(line + newline);
101   - }
102   -});
103   -```
104   -
105   -*Note: `file` can be omitted if you want to work with stdin*
106   -
107   -To output a progress bar, call
108   -
109   -```javascript
110   -cli.progress(progress); //Where 0 <= progress <= 1
111   -```
112   -
113   -To spawn a child process, use
114   -
115   -```javascript
116   -cli.exec(cmd, callback); //callback receives the output of the process (split into lines)
117   -```
118   -
119   -cli also comes bundled with kof's [node-natives](https://github.com/kof/node-natives) (access with cli.native) and creationix' [stack](https://github.com/creationix/stack) (access with cli.createServer)
120   -
121   -## Plugins
122   -
123   -Plugins are a way of adding common opts and can be enabled using
124   -
125   -```javascript
126   -cli.enable(plugin1, [plugin2, ...]); //To disable, use the equivalent disable() method
127   -```
128   -
129   -**help** - *enabled by default*
130   -
131   -Adds `-h,--help` to output auto-generated usage information
132   -
133   -**version**
134   -
135   -Adds `-v,--version` to output version information for the app. cli will attempt to locate and parse a nearby *package.json*
136   -
137   -To set your own app name and version, use `cli.setApp(app_name, version)`
138   -
139   -**status**
140   -
141   -Adds options to show/hide the stylized status messages that are output to the console when using one of these methods
142   -
143   -```javascript
144   -cli.debug(msg); //Only shown when using --debug
145   -cli.error(msg);
146   -cli.fatal(msg); //Exits the process after outputting msg
147   -cli.info(msg);
148   -cli.ok(msg);
149   -```
150   -
151   -`-k,--no-color` will omit ANSI color escapes from the output
152   -
153   -**glob** - *requires* `npm install glob`
154   -
155   -Enables glob matching of arguments
156   -
157   -**daemon** - *requires* `npm install daemon`
158   -
159   -Adds `-d,--daemon ARG` for daemonizing the process and controlling the resulting daemon
160   -
161   -`ARG` can be either start (default), stop, restart, pid (outputs the daemon's pid if it's running), or log (output the daemon's stdout+stderr)
162   -
163   -**timeout**
164   -
165   -Adds `-t,--timeout N` to exit the process after N seconds with an error
166   -
167   -**catchall**
168   -
169   -Adds `-c,--catch` to catch and output uncaughtExceptions and resume execution
170   -
171   -*Note: Plugins are automatically disabled if an option or switch of the same name is already defined*
172   -
173   -## LICENSE
174   -
175   -(MIT license)
176   -
177   -Copyright (c) 2010 Chris O'Hara <cohara87@gmail.com>
178   -
179   -Permission is hereby granted, free of charge, to any person obtaining
180   -a copy of this software and associated documentation files (the
181   -"Software"), to deal in the Software without restriction, including
182   -without limitation the rights to use, copy, modify, merge, publish,
183   -distribute, sublicense, and/or sell copies of the Software, and to
184   -permit persons to whom the Software is furnished to do so, subject to
185   -the following conditions:
186   -
187   -The above copyright notice and this permission notice shall be
188   -included in all copies or substantial portions of the Software.
189   -
190   -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
191   -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
192   -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
193   -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
194   -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
195   -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
196   -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1,125 node_modules/cli/cli.js
... ... @@ -1,1125 +0,0 @@
1   -/**
2   - * Copyright (c) 2010 Chris O'Hara <cohara87@gmail.com>
3   - *
4   - * Permission is hereby granted, free of charge, to any person obtaining
5   - * a copy of this software and associated documentation files (the
6   - * "Software"), to deal in the Software without restriction, including
7   - * without limitation the rights to use, copy, modify, merge, publish,
8   - * distribute, sublicense, and/or sell copies of the Software, and to
9   - * permit persons to whom the Software is furnished to do so, subject to
10   - * the following conditions:
11   - *
12   - * The above copyright notice and this permission notice shall be
13   - * included in all copies or substantial portions of the Software.
14   - *
15   - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16   - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17   - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18   - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19   - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20   - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21   - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22   - */
23   -
24   - //Note: cli includes kof/node-natives and creationix/stack. I couldn't find
25   - //license information for either - contact me if you want your license added
26   -
27   -var cli = exports,
28   - argv, curr_opt, curr_val, full_opt, is_long,
29   - short_tags = [], opt_list, parsed = {},
30   - usage, argv_parsed, command_list, commands,
31   - daemon, daemon_arg, no_color, show_debug;
32   -
33   -cli.app = null;
34   -cli.version = null;
35   -cli.argv = [];
36   -cli.argc = 0;
37   -
38   -cli.options = {};
39   -cli.args = [];
40   -cli.command;
41   -
42   -cli.width = 70;
43   -cli.option_width = 25;
44   -
45   -/**
46   - * Bind kof's node-natives (https://github.com/kof/node-natives) to `cli.native`
47   - *
48   - * Rather than requiring node natives (e.g. var fs = require('fs')), all
49   - * native modules can be accessed like `cli.native.fs`
50   - */
51   -cli.native = {};
52   -var define_native = function (module) {
53   - Object.defineProperty(cli.native, module, {
54   - enumerable: true,
55   - configurable: true,
56   - get: function() {
57   - delete cli.native[module];
58   - return cli.native[module] = require(module);
59   - }
60   - });
61   -};
62   -var natives = process.binding('natives');
63   -for (var module in natives) {
64   - define_native(module);
65   -}
66   -
67   -cli.output = cli.native.util.print;
68   -cli.exit = process.exit;
69   -
70   -/**
71   - * Define plugins. Plugins can be enabled and disabled by calling:
72   - *
73   - * `cli.enable(plugin1, [plugin2, ...])`
74   - * `cli.disable(plugin1, [plugin2, ...])`
75   - *
76   - * Methods are chainable - `cli.enable(plugin).disable(plugin2)`.
77   - *
78   - * The 'help' plugin is enabled by default.
79   - */
80   -var enable = {
81   - help: true, //Adds -h, --help
82   - version: false, //Adds -v,--version => gets version by parsing a nearby package.json
83   - daemon: false, //Adds -d,--daemon [ARG] => (see cli.daemon() below)
84   - status: false, //Adds -k,--no-color & --debug => display plain status messages /display debug messages
85   - timeout: false, //Adds -t,--timeout N => timeout the process after N seconds
86   - catchall: false, //Adds -c,--catch => catch and output uncaughtExceptions
87   - glob: false //Adds glob matching => use cli.glob(arg)
88   -}
89   -cli.enable = function (/*plugins*/) {
90   - Array.prototype.slice.call(arguments).forEach(function (plugin) {
91   - switch (plugin) {
92   - case 'daemon':
93   - try {
94   - daemon = require('daemon');
95   - if (typeof daemon.daemonize !== 'function') {
96   - throw 'Invalid module';
97   - }
98   - } catch (e) {
99   - cli.fatal('daemon.node not installed. Please run `npm install daemon`');
100   - }
101   - break;
102   - case 'catchall':
103   - process.on('uncaughtException', function (err) {
104   - cli.error('Uncaught exception: ' + (err.msg || err));
105   - });
106   - break;
107   - case 'help': case 'version': case 'status':
108   - case 'autocomplete': case 'timeout':
109   - //Just add switches.
110   - break;
111   - case 'glob':
112   - try {
113   - glob = require('glob');
114   - if (typeof glob.glob !== 'function') {
115   - throw 'Invalid module';
116   - }
117   - } catch (e) {
118   - cli.fatal('glob not installed. Please run `npm install glob`');
119   - }
120   - cli.glob = glob.glob;
121   - cli.globSync = glob.globSync;
122   - break;
123   - default:
124   - cli.fatal('Unknown plugin "' + plugin + '"');
125   - break;
126   - }
127   - enable[plugin] = true;
128   - });
129   - return cli;
130   -}
131   -cli.disable = function (/*plugins*/) {
132   - Array.prototype.slice.call(arguments).forEach(function (plugin) {
133   - if (enable[plugin]) {
134   - enable[plugin] = false;
135   - }
136   - });
137   - return cli;
138   -}
139   -
140   -/**
141   - * Sets argv (default is process.argv).
142   - *
143   - * @param {Array|String} argv
144   - * @param {Boolean} keep_arg0 (optional - default is false)
145   - * @api public
146   - */
147   -cli.setArgv = function (arr, keep_arg0) {
148   - if (typeof arr == 'string') {
149   - arr = arr.split(' ');
150   - } else {
151   - arr = arr.slice();
152   - }
153   - cli.app = arr.shift();
154   - //Strip off argv[0] if it's 'node'
155   - if (!keep_arg0 && 'node' === cli.native.path.basename(cli.app)) {
156   - cli.app = arr.shift();
157   - }
158   - cli.app = cli.native.path.basename(cli.app);
159   - argv_parsed = false;
160   - cli.args = cli.argv = argv = arr;
161   - cli.argc = argv.length;
162   -};
163   -cli.setArgv(process.argv);
164   -
165   -/**
166   - * Returns the next opt, or false if no opts are found.
167   - *
168   - * @return {String} opt
169   - * @api public
170   - */
171   -cli.next = function () {
172   - if (!argv_parsed) {
173   - cli.args = [];
174   - argv_parsed = true;
175   - }
176   -
177   - curr_val = null;
178   -
179   - //If we're currently in a group of short opts (e.g. -abc), return the next opt
180   - if (short_tags.length) {
181   - curr_opt = short_tags.shift();
182   - full_opt = '-' + curr_opt;
183   - return curr_opt;
184   - }
185   -
186   - if (!argv.length) {
187   - return false;
188   - }
189   -
190   - curr_opt = argv.shift();
191   -
192   - //If an escape sequence is found (- or --), subsequent opts are ignored
193   - if (curr_opt === '-' || curr_opt === '--') {
194   - while (argv.length) {
195   - cli.args.push(argv.shift());
196   - }
197   - return false;
198   - }
199   -
200   - //If the next element in argv isn't an opt, add it to the list of args
201   - if (curr_opt[0] !== '-') {
202   - cli.args.push(curr_opt);
203   - return cli.next();
204   - } else {
205   - //Check if the opt is short/long
206   - is_long = curr_opt[1] === '-';
207   - curr_opt = curr_opt.substr(is_long ? 2 : 1);
208   - }
209   -
210   - //Accept grouped short opts, e.g. -abc => -a -b -c
211   - if (!is_long && curr_opt.length > 1) {
212   - short_tags = curr_opt.split('');
213   - return cli.next();
214   - }
215   -
216   - var eq, len;
217   -
218   - //Check if the long opt is in the form --option=VALUE
219   - if (is_long && (eq = curr_opt.indexOf('=')) >= 0) {
220   - curr_val = curr_opt.substr(eq + 1);
221   - curr_opt = curr_opt.substr(0, eq);
222   - len = curr_val.length;
223   - //Allow values to be quoted
224   - if ((curr_val[0] === '"' && curr_val[len - 1] === '"') ||
225   - (curr_val[0] === "'" && curr_val[len - 1] === "'"))
226   - {
227   - curr_val = curr_val.substr(1, len-2);
228   - }
229   - if (curr_val.match(/^[0-9]+$/)) {
230   - curr_val = parseInt(curr_val, 10);
231   - }
232   - }
233   -
234   - //Save the opt representation for later
235   - full_opt = (is_long ? '--' : '-') + curr_opt;
236   -
237   - return curr_opt;
238   -};
239   -
240   -/**
241   - * Parses command line opts.
242   - *
243   - * `opts` must be an object with opts defined like:
244   - * long_tag: [short_tag, description, value_type, default_value];
245   - *
246   - * `commands` is an optional array or object for apps that are of the form
247   - * my_app [OPTIONS] <command> [ARGS]
248   - * The command list is output with usage information + there is bundled
249   - * support for auto-completion, etc.
250   - *
251   - * See README.md for more information.
252   - *
253   - * @param {Object} opts
254   - * @param {Object} commands (optional)
255   - * @return {Object} opts (parsed)
256   - * @api public
257   - */
258   -cli.parse = function (opts, command_def) {
259   - var default_val, i, parsed = cli.options, seen,
260   - catch_all = !opts;
261   - opt_list = opts || {};
262   - commands = command_def;
263   - command_list = commands || [];
264   - if (commands && !Array.isArray(commands)) {
265   - command_list = Object.keys(commands);
266   - }
267   - while (o = cli.next()) {
268   - seen = false;
269   - for (opt in opt_list) {
270   - if (!(opt_list[opt] instanceof Array)) {
271   - continue;
272   - }
273   - if (opt_list[opt][0] === false) {
274   - opt_list[opt][0] = opt;
275   - }
276   - if (o === opt || o === opt_list[opt][0]) {
277   - seen = true;
278   - if (opt_list[opt].length === 2) {
279   - parsed[opt] = true;
280   - break;
281   - }
282   - default_val = null;
283   - if (opt_list[opt].length === 4) {
284   - default_val = opt_list[opt][3];
285   - }
286   - if (opt_list[opt][2] instanceof Array) {
287   - for (i = 0, l = opt_list[opt][2].length; i < l; i++) {
288   - if (typeof opt_list[opt][2][i] === 'number') {
289   - opt_list[opt][2][i] += '';
290   - }
291   - }
292   - parsed[opt] = cli.getArrayValue(opt_list[opt][2], is_long ? null : default_val);
293   - break;
294   - }
295   - if (opt_list[opt][2].toLowerCase) {
296   - opt_list[opt][2] = opt_list[opt][2].toLowerCase();
297   - }
298   - switch (opt_list[opt][2]) {
299   - case 'string': case 1: case true:
300   - parsed[opt] = cli.getValue(default_val);
301   - break;
302   - case 'int': case 'number': case 'num':
303   - case 'time': case 'seconds': case 'secs': case 'minutes': case 'mins':
304   - case 'x': case 'n':
305   - parsed[opt] = cli.getInt(default_val);
306   - break;
307   - case 'float': case 'decimal':
308   - parsed[opt] = cli.getFloat(default_val);
309   - break;
310   - case 'path': case 'file': case 'directory': case 'dir':
311   - parsed[opt] = cli.getPath(default_val, opt_list[opt][2]);
312   - break;
313   - case 'email':
314   - parsed[opt] = cli.getEmail(default_val);
315   - break;
316   - case 'url': case 'uri': case 'domain': case 'host':
317   - parsed[opt] = cli.getUrl(default_val, opt_list[opt][2]);
318   - break;
319   - case 'ip':
320   - parsed[opt] = cli.getIp(default_val);
321   - break;
322   - case 'bool': case 'boolean': case 'on':
323   - parsed[opt] = true;
324   - break;
325   - case 'false': case 'off': case false: case 0:
326   - parsed[opt] = false;
327   - break;
328   - default:
329   - cli.fatal('Unknown opt type "' + opt_list[opt][2] + '"');
330   - }
331   - break;
332   - }
333   - }
334   - if (!seen) {
335   - if (enable.help && (o === 'h' || o === 'help')) {
336   - cli.getUsage();
337   - process.exit();
338   - } else if (enable.version && (o === 'v' || o === 'version')) {
339   - if (typeof cli.version === 'undefined') {
340   - cli.parsePackageJson();
341   - }
342   - console.error(cli.app + ' v' + cli.version);
343   - process.exit();
344   - } else if (enable.daemon && (o === 'd' || o === 'daemon')) {
345   - daemon_arg = cli.getArrayValue(['start','stop','restart','pid','log'], is_long ? null : 'start');
346   - continue;
347   - } else if (enable.catchall && (o === 'c' || o === 'catch')) {
348   - continue;
349   - } else if (enable.status && (o === 'k' || o === 'no-color' || o === 'debug')) {
350   - no_color = (o === 'k' || o === 'no-color');
351   - show_debug = o === 'debug';
352   - continue;
353   - } else if (enable.timeout && (o === 't' || o === 'timeout')) {
354   - var secs = cli.getInt();
355   - setTimeout(function () {
356   - cli.fatal('Process timed out after ' + secs + 's');
357   - }, secs * 1000);
358   - continue;
359   - } else if (catch_all) {
360   - parsed[o] = curr_val || true;
361   - continue;
362   - }
363   - cli.fatal('Unknown option ' + full_opt);
364   - }
365   - }
366   - //Fill the remaining options with their default value or null
367   - for (opt in opt_list) {
368   - default_val = opt_list[opt].length === 4 ? opt_list[opt][3] : null;
369   - if (!(opt_list[opt] instanceof Array)) {
370   - parsed[opt] = opt_list[opt];
371   - continue;
372   - } else if (typeof parsed[opt] === 'undefined') {
373   - parsed[opt] = default_val;
374   - }
375   - }
376   - if (command_list.length) {
377   - if (cli.args.length === 0) {
378   - if (enable.help) {
379   - cli.getUsage();
380   - } else {
381   - cli.fatal('A command is required (' + command_list.join(', ') + ').');
382   - }
383   - process.exit(1);
384   - } else {
385   - cli.command = cli.autocompleteCommand(cli.args.shift());
386   - }
387   - }
388   - cli.argc = cli.args.length;
389   - return parsed;
390   -};
391   -
392   -/**
393   - * Helper method for matching a command from the command list.
394   - *
395   - * @param {String} command
396   - * @return {String} full_command
397   - * @api public
398   - */
399   -cli.autocompleteCommand = function (command) {
400   - var list;
401   - if (!(command_list instanceof Array)) {
402   - list = Object.keys(command_list);
403   - } else {
404   - list = command_list;
405   - }
406   - var i, j = 0, c = command.length, tmp_list;
407   - if (list.length === 0 || list.indexOf(command) !== -1) {
408   - return command;
409   - }
410   - for (i = 0; i < c; i++) {
411   - tmp_list = [];
412   - l = list.length;
413   - if (l <= 1) break;
414   - for (j = 0; j < l; j++)
415   - if (list[j].length >= i && list[j][i] === command[i])
416   - tmp_list.push(list[j]);
417   - list = tmp_list;
418   - }
419   - l = list.length;
420   - if (l === 1) {
421   - return list[0];
422   - } else if (l === 0) {
423   - cli.fatal('Unknown command "' + command + '"' + (enable.help ? '. Please see --help for more information' : ''));
424   - } else {
425   - list.sort();
426   - cli.fatal('The command "' + command + '" is ambiguous and could mean "' + list.join('", "') + '"');
427   - }
428   -};
429   -
430   -/**
431   - * Adds methods to output styled status messages to stderr.
432   - *
433   - * Added methods are cli.info(msg), cli.error(msg), cli.ok(msg), and
434   - * cli.debug(msg).
435   - *
436   - * To control status messages, use the 'status' plugin
437   - * 1) debug() messages are hidden by default. Display them with
438   - * the --debug opt.
439   - * 2) to hide all status messages, use the -s or --silent opt.
440   - *
441   - * @api private
442   - */
443   -cli.status = function (msg, type) {
444   - var pre;
445   - switch (type) {
446   - case 'info':
447   - pre = no_color ? 'INFO:' : '\x1B[33mINFO\x1B[0m:';
448   - break;
449   - case 'debug':
450   - pre = no_color ? 'DEBUG:' : '\x1B[36mDEBUG\x1B[0m:';
451   - break;
452   - case 'error':
453   - case 'fatal':
454   - pre = no_color ? 'ERROR:' : '\x1B[31mERROR\x1B[0m:';
455   - break;
456   - case 'ok':
457   - pre = no_color ? 'OK:' : '\x1B[32mOK\x1B[0m:';
458   - break;
459   - }
460   - msg = pre + ' ' + msg;
461   - if (type === 'fatal') {
462   - console.error(msg);
463   - process.exit(1);
464   - }
465   - if (enable.status && !show_debug && type === 'debug') {
466   - return;
467   - }
468   - console.error(msg);
469   -};
470   -['info','error','ok','debug','fatal'].forEach(function (type) {
471   - cli[type] = function (msg) {
472   - cli.status(msg, type);
473   - };
474   -});
475   -
476   -/**
477   - * Sets the app name and version.
478   - *
479   - * Usage:
480   - * setApp('myapp', '0.1.0');
481   - * setApp('./package.json'); //Pull name/version from package.json
482   - *
483   - * @param {String} name
484   - * @return cli (for chaining)
485   - * @api public
486   - */
487   -cli.setApp = function (name, version) {
488   - if (name.indexOf('package.json') !== -1) {
489   - cli.parsePackageJson(name);
490   - } else {
491   - cli.app = name;
492   - cli.version = version;
493   - }
494   - return cli;
495   -};
496   -
497   -/**
498   - * Parses the version number from package.json. If no path is specified, cli
499   - * will attempt to locate a package.json in ./, ../ or ../../
500   - *
501   - * @param {String} path (optional)
502   - * @api public
503   - */
504   -cli.parsePackageJson = function (path) {
505   - var parse_packagejson = function (path) {
506   - var packagejson = JSON.parse(cli.native.fs.readFileSync(path, 'utf8'));
507   - cli.version = packagejson.version;
508   - cli.app = packagejson.name;
509   - };
510   - var try_all = function (arr, func, err) {
511   - for (var i = 0, l = arr.length; i < l; i++) {
512   - try {
513   - func(arr[i]);
514   - return;
515   - } catch (e) {
516   - if (i === l-1) {
517   - cli.fatal(err);
518   - }
519   - }
520   - }
521   - };
522   - try {
523   - if (path) {
524   - return parse_packagejson(path);
525   - }
526   - try_all([
527   - __dirname + '/package.json',
528   - __dirname + '/../package.json',
529   - __dirname + '/../../package.json'
530   - ], parse_packagejson);
531   - } catch (e) {
532   - cli.fatal('Could not detect ' + cli.app + ' version');
533   - }
534   -};
535   -
536   -/**
537   - * Sets the usage string - default is `app [OPTIONS] [ARGS]`.
538   - *
539   - * @param {String} u
540   - * @return cli (for chaining)
541   - * @api public
542   - */
543   -cli.setUsage = function (u) {
544   - usage = u;
545   - return cli;
546   -};
547   -
548   -var pad = function (str, len) {
549   - if (typeof len === 'undefined') {
550   - len = str;
551   - str = '';
552   - }
553   - if (str.length < len) {
554   - len -= str.length;
555   - while (len--) str += ' ';
556   - }
557   - return str;
558   -};
559   -
560   -/**
561   - * Automatically build usage information from the opts list. If the help
562   - * plugin is enabled (default), this info is displayed with -h, --help.
563   - *
564   - * @api public
565   - */
566   -cli.getUsage = function () {
567   - var short, desc, optional, line, seen_opts = [],
568   - switch_pad = cli.option_width;
569   -
570   - var trunc_desc = function (pref, desc, len) {
571   - var pref_len = pref.length,
572   - desc_len = cli.width - pref_len,
573   - truncated = '';
574   - if (desc.length <= desc_len) {
575   - return desc;
576   - }
577   - var desc_words = (desc+'').split(' '), chars = 0, word;
578   - while (desc_words.length) {
579   - truncated += (word = desc_words.shift()) + ' ';
580   - chars += word.length;
581   - if (desc_words.length && chars + desc_words[0].length > desc_len) {
582   - truncated += '\n' + pad(pref_len);
583   - chars = 0;
584   - }
585   - }
586   - return truncated;
587   - };
588   -
589   - usage = usage || cli.app + ' [OPTIONS]' + (command_list ? ' <command>' : '') + ' [ARGS]';
590   - console.error('\x1b[1mUsage\x1b[0m:\n ' + usage);
591   - console.error('\n\x1b[1mOptions\x1b[0m: ');
592   - for (opt in opt_list) {
593   -
594   - if (opt.length === 1) {
595   - long = opt_list[opt][0];
596   - short = opt;
597   - } else {
598   - long = opt;
599   - short = opt_list[opt][0];
600   - }
601   -
602   - //Parse opt_list
603   - desc = opt_list[opt][1].trim();
604   - type = opt_list[opt].length >= 3 ? opt_list[opt][2] : null;
605   - optional = opt_list[opt].length === 4 ? opt_list[opt][3] : null;
606   -
607   - //Build usage line
608   - if (short === long) {
609   - if (short.length === 1) {
610   - line = ' -' + short;
611   - } else {
612   - line = ' --' + long;
613   - }
614   - } else {
615   - line = ' -' + short + ', --' + long;
616   - }
617   - line += ' ';
618   -
619   - if (type) {
620   - if (type instanceof Array) {
621   - desc += '. VALUE must be either [' + type.join('|') + ']';
622   - type = 'VALUE';
623   - }
624   - if (type === true || type === 1) {
625   - type = long.toUpperCase();
626   - }
627   - type = type.toUpperCase();
628   - if (type === 'FLOAT' || type === 'INT') {
629   - type = 'NUMBER';
630   - }
631   - line += optional ? '[' + type + ']' : type;
632   - }
633   - line = pad(line, switch_pad);
634   - line += trunc_desc(line, desc);
635   - line += optional ? ' (Default is ' + optional + ')' : '';
636   - console.error(line.replace('%s', '%\0s'));
637   -
638   - seen_opts.push(short);
639   - seen_opts.push(long);
640   - }
641   - if (enable.timeout && seen_opts.indexOf('t') === -1 && seen_opts.indexOf('timeout') === -1) {
642   - console.error(pad(' -t, --timeout N', switch_pad) + 'Exit if the process takes longer than N seconds');
643   - }
644   - if (enable.status) {
645   - if (seen_opts.indexOf('k') === -1 && seen_opts.indexOf('no-color') === -1) {
646   - console.error(pad(' -k, --no-color', switch_pad) + 'Omit color from output');
647   - }
648   - if (seen_opts.indexOf('debug') === -1) {
649   - console.error(pad(' --debug', switch_pad) + 'Show debug information');
650   - }
651   - }
652   - if (enable.catchall && seen_opts.indexOf('c') === -1 && seen_opts.indexOf('catch') === -1) {
653   - console.error(pad(' -c, --catch', switch_pad) + 'Catch unanticipated errors');
654   - }
655   - if (enable.daemon && seen_opts.indexOf('d') === -1 && seen_opts.indexOf('daemon') === -1) {
656   - console.error(pad(' -d, --daemon [ARG]', switch_pad) + 'Daemonize the process. Control the daemon using [start, stop, restart, log, pid]');
657   - }
658   - if (enable.version && seen_opts.indexOf('v') === -1 && seen_opts.indexOf('version') === -1) {
659   - console.error(pad(' -v, --version', switch_pad) + 'Display the current version');
660   - }
661   - if (enable.help && seen_opts.indexOf('h') === -1 && seen_opts.indexOf('help') === -1) {
662   - console.error(pad(' -h, --help', switch_pad) + 'Display help and usage details');
663   - }
664   - if (command_list.length) {
665   - console.error('\n\x1b[1mCommands\x1b[0m: ');
666   - if (!Array.isArray(commands)) {
667   - for (var c in commands) {
668   - line = ' ' + pad(c, switch_pad - 2);
669   - line += trunc_desc(line, commands[c]);
670   - console.error(line);
671   - }
672   - } else {
673   - command_list.sort();
674   - console.error(' ' + trunc_desc(' ', command_list.join(', ')));
675   - }
676   - }
677   - process.exit();
678   -};
679   -
680   -/**
681   - * Generates an error message when an opt is incorrectly used.
682   - *
683   - * @param {String} expects (e.g. 'a value')
684   - * @param {String} type (e.g. 'VALUE')
685   - * @api public
686   - */
687   -cli.getOptError = function (expects, type) {
688   - var err = full_opt + ' expects ' + expects
689   - + '. Use `' + cli.app + ' ' + full_opt + (is_long ? '=' : ' ') + type + '`';
690   - return err;
691   -};
692   -
693   -/**
694   - * Gets the next opt value and validates it with an optional validation
695   - * function. If validation fails or no value can be obtained, this method
696   - * will return the default value (if specified) or exit with err_msg.
697   - *
698   - * @param {String} default_val
699   - * @param {Function} validate_func
700   - * @param {String} err_msg
701   - * @api public
702   - */
703   -cli.getValue = function (default_val, validate_func, err_msg) {
704   - err_msg = err_msg || cli.getOptError('a value', 'VALUE');
705   -
706   - var value;
707   -
708   - try {
709   - if (curr_val) {
710   - if (validate_func) {
711   - curr_val = validate_func(curr_val);
712   - }
713   - return curr_val;
714   - }
715   -
716   - //Grouped short opts aren't allowed to have values
717   - if (short_tags.length) {
718   - throw 'Short tags';
719   - }
720   -
721   - //If there's no args left or the next arg is an opt, return the
722   - //default value (if specified) - otherwise fail
723   - if (!argv.length || argv[0][0] === '-') {
724   - throw 'No value';
725   - }
726   -
727   - value = argv.shift();
728   -
729   - if (value.match(/^[0-9]+$/)) {
730   - value = parseInt(value, 10);
731   - }
732   -
733   - //Run the value through a validation/transformation function if specified
734   - if (validate_func) {
735   - value = validate_func(value);
736   - }
737   - } catch (e) {
738   -
739   - //The value didn't pass the validation/transformation. Unshift the value and
740   - //return the default value (if specified)
741   - if (value) {
742   - argv.unshift(value);
743   - }
744   - return default_val != null ? default_val : cli.fatal(err_msg);
745   - }
746   - return value;
747   -};
748   -
749   -cli.getInt = function (default_val) {
750   - return cli.getValue(default_val, function (value) {
751   - if (typeof value === 'number') return value;
752   - if (!value.match(/^(?:-?(?:0|[1-9][0-9]*))$/)) {
753   - throw 'Invalid int';
754   - }
755   - return parseInt(value);
756   - }, cli.getOptError('a number', 'NUMBER'));
757   -}
758   -
759   -cli.getFloat = function (default_val) {
760   - return cli.getValue(default_val, function (value) {
761   - if (!value.match(/^(?:-?(?:0|[1-9][0-9]*))?(?:\.[0-9]*)?$/)) {
762   - throw 'Invalid float';
763   - }
764   - return parseFloat(value, 10);
765   - }, cli.getOptError('a number', 'NUMBER'));
766   -}
767   -
768   -cli.getUrl = function (default_val, identifier) {
769   - identifier = identifier || 'url';
770   - return cli.getValue(default_val, function (value) {
771   - if (!value.match(/^(?:(?:ht|f)tp(?:s?)\:\/\/|~\/|\/)?(?:\w+:\w+@)?((?:(?:[-\w\d{1-3}]+\.)+(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|edu|co\.uk|ac\.uk|it|fr|tv|museum|asia|local|travel|[a-z]{2})?)|((\b25[0-5]\b|\b[2][0-4][0-9]\b|\b[0-1]?[0-9]?[0-9]\b)(\.(\b25[0-5]\b|\b[2][0-4][0-9]\b|\b[0-1]?[0-9]?[0-9]\b)){3}))(?::[\d]{1,5})?(?:(?:(?:\/(?:[-\w~!$+|.,=]|%[a-f\d]{2})+)+|\/)+|\?|#)?(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?:#(?:[-\w~!$ |\/.,*:;=]|%[a-f\d]{2})*)?$/)) {
772   - throw 'Invalid URL';
773   - }
774   - return value;
775   - }, cli.getOptError('a ' + identifier, identifier.toUpperCase()));
776   -}
777   -
778   -cli.getEmail = function (default_val) {
779   - return cli.getValue(default_val, function (value) {
780   - if (!value.match(/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/)) {
781   - throw 'Invalid email';
782   - }
783   - return value;
784   - }, cli.getOptError('an email', 'EMAIL'));
785   -}
786   -
787   -cli.getIp = function (default_val) {
788   - return cli.getValue(default_val, function (value) {
789   - if (!value.match(/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/)) {
790   - throw 'Invalid IP';
791   - }
792   - return value;
793   - }, cli.getOptError('an IP', 'IP'));
794   -}
795   -
796   -cli.getPath = function (default_val, identifier) {
797   - identifier = identifier || 'path';
798   - return cli.getValue(default_val, function (value) {
799   - if (value.match(/[?*:;{}]/)) {
800   - throw 'Invalid path';
801   - }
802   - return value;
803   - }, cli.getOptError('a ' + identifier, identifier.toUpperCase()));
804   -}
805   -
806   -cli.getArrayValue = function (arr, default_val) {
807   - return cli.getValue(default_val, function (value) {
808   - if (arr.indexOf(value) === -1) {
809   - throw 'Unexpected value';
810   - }
811   - return value;
812   - }, cli.getOptError('either [' + arr.join('|') + ']', 'VALUE'));
813   -}
814   -
815   -/**
816   - * Gets all data from STDIN (with optional encoding) and sends it to callback.
817   - *
818   - * @param {String} encoding (optional - default is 'utf8')
819   - * @param {Function} callback
820   - * @api public
821   - */
822   -cli.withStdin = function (encoding, callback) {
823   - if (typeof encoding === 'function') {
824   - callback = encoding;
825   - encoding = 'utf8';
826   - }
827   - var stream = process.openStdin(), data = '';
828   - stream.setEncoding(encoding);
829   - stream.on('data', function (chunk) {
830   - data += chunk;
831   - });
832   - stream.on('end', function () {
833   - callback.apply(cli, [data]);
834   - });
835   -};
836   -
837   -/**
838   - * Gets all data from STDIN, splits the data into lines and sends it
839   - * to callback (callback isn't called until all of STDIN is read. To
840   - * process each line as it's received, see the method below
841   - *
842   - * @param {Function} callback
843   - * @api public
844   - */
845   -cli.withStdinLines = function (callback) {
846   - cli.withStdin(function (data) {
847   - var sep = data.indexOf('\r\n') !== -1 ? '\r\n' : '\n';
848   - callback.apply(cli, [data.split(sep), sep]);
849   - });
850   -};
851   -
852   -/**
853   - * Asynchronously reads a file line by line. When a line is received,
854   - * callback is called with (line, sep) - when EOF is reached, callback
855   - * receives (null, null, true)
856   - *
857   - * @param {String} file (optional - default is 'stdin')
858   - * @param {String} encoding (optional - default is 'utf8')
859   - * @param {Function} callback (line, sep, eof)
860   - * @api public
861   - */
862   -cli.withInput = function (file, encoding, callback) {
863   - if (typeof encoding === 'function') {
864   - callback = encoding;
865   - encoding = 'utf8';
866   - } else if (typeof file === 'function') {
867   - callback = file;
868   - encoding = 'utf8';
869   - file = 'stdin';
870   - }
871   - if (file === 'stdin') {
872   - file = process.openStdin();
873   - } else {
874   - try {
875   - file = cli.native.fs.createReadStream(file);
876   - file.on('error', cli.fatal);
877   - } catch (e) {
878   - return cli.fatal(e);
879   - }
880   - }
881   - file.setEncoding(encoding);
882   - var lines = [], data = '', eof, sep;
883   - file.on('data', function (chunk) {
884   - if (eof) return;
885   - data += chunk;
886   - if (!sep) {
887   - if (data.indexOf('\r\n') !== -1) {
888   - sep = '\r\n';
889   - } else if (data.indexOf('\n') !== -1) {
890   - sep = '\n';
891   - } else {
892   - last_line = data;
893   - return;
894   - }
895   - }
896   - lines = data.split(sep);
897   - data = eof ? null : lines.pop();
898   - while (lines.length) {
899   - callback.apply(cli, [lines.shift(), sep, false]);
900   - }
901   - });
902   - file.on('end', function () {
903   - eof = true;
904   - if (data.length) {
905   - callback.apply(cli, [data, sep || '', false]);
906   - }
907   - callback.apply(cli, [null, null, true]);
908   - });
909   -};
910   -
911   -/**
912   - * A method for creating and controlling a daemon.
913   - *
914   - * `arg` can be:
915   - * start = daemonizes the process
916   - * stop = stops the daemon if it is running
917   - * restart = alias for stop -> start
918   - * pid = outputs the daemon's PID if it is running
919   - * log = outputs the daemon's log file (stdout + stderr)
920   - *
921   - * @param {String} arg (Optional - default is 'start')
922   - * @param {Function} callback
923   - * @api public
924   - */
925   -cli.daemon = function (arg, callback) {
926   - if (typeof daemon === 'undefined') {
927   - cli.fatal('Daemon is not initialized');
928   - }
929   -
930   - if (typeof arg === 'function') {
931   - callback = arg;
932   - arg = 'start';
933   - }
934   -
935   - var lock_file = '/tmp/' + cli.app + '.pid',
936   - log_file = '/tmp/' + cli.app + '.log';
937   -
938   - var start = function () {
939   - daemon.daemonize(log_file, lock_file, function (err) {
940   - if (err) return cli.error('Error starting daemon: ' + err);
941   - callback();
942   - });
943   - };
944   -
945   - var stop = function () {
946   - try {
947   - cli.native.fs.readFileSync(lock_file);
948   - } catch (e) {
949   - return cli.error('Daemon is not running');
950   - };
951   - daemon.kill(lock_file, function (err, pid) {
952   - if (err && err.errno === 3) {
953   - return cli.error('Daemon is not running');
954   - } else if (err) {
955   - return cli.error('Error stopping daemon: ' + err.errno);
956   - }
957   - cli.ok('Successfully stopped daemon with pid: ' + pid);
958   - });
959   - };
960   -
961   - switch(arg) {
962   - case 'stop':
963   - stop();
964   - break;
965   - case 'restart':
966   - daemon.stop(lock_file, function () {
967   - start();
968   - });
969   - break;
970   - case 'log':
971   - try {
972   - cli.native.fs.createReadStream(log_file, {encoding: 'utf8'}).pipe(process.stdout);
973   - } catch (e) {
974   - return cli.error('No daemon log file');
975   - };
976   - break;
977