1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-12 10:52:47 +00:00

updated bunch of file paths and changed the way posts are loaded

This commit is contained in:
2016-01-05 12:28:04 -06:00
parent 719ae331ae
commit c96a84d0ff
13249 changed files with 317868 additions and 2101398 deletions

511
node_modules/dashdash/README.md generated vendored Normal file
View File

@@ -0,0 +1,511 @@
A light, featureful and explicit option parsing library for node.js.
[Why another one? See below](#why). tl;dr: The others I've tried are one of
too loosey goosey (not explicit), too big/too many deps, or ill specified.
YMMV.
Follow <a href="https://twitter.com/intent/user?screen_name=trentmick" target="_blank">@trentmick</a>
for updates to node-dashdash.
# Install
npm install dashdash
# Usage
```javascript
var dashdash = require('dashdash');
// Specify the options. Minimally `name` (or `names`) and `type`
// must be given for each.
var options = [
{
// `names` or a single `name`. First element is the `opts.KEY`.
names: ['help', 'h'],
// See "Option specs" below for types.
type: 'bool',
help: 'Print this help and exit.'
}
];
// Shortcut form. As called it infers `process.argv`. See below for
// the longer form to use methods like `.help()` on the Parser object.
var opts = dashdash.parse({options: options});
console.log("opts:", opts);
console.log("args:", opts._args);
```
# Longer Example
A more realistic [starter script "foo.js"](./examples/foo.js) is as follows.
This also shows using `parser.help()` for formatted option help.
```javascript
var dashdash = require('./lib/dashdash');
var options = [
{
name: 'version',
type: 'bool',
help: 'Print tool version and exit.'
},
{
names: ['help', 'h'],
type: 'bool',
help: 'Print this help and exit.'
},
{
names: ['verbose', 'v'],
type: 'arrayOfBool',
help: 'Verbose output. Use multiple times for more verbose.'
},
{
names: ['file', 'f'],
type: 'string',
help: 'File to process',
helpArg: 'FILE'
}
];
var parser = dashdash.createParser({options: options});
try {
var opts = parser.parse(process.argv);
} catch (e) {
console.error('foo: error: %s', e.message);
process.exit(1);
}
console.log("# opts:", opts);
console.log("# args:", opts._args);
// Use `parser.help()` for formatted options help.
if (opts.help) {
var help = parser.help({includeEnv: true}).trimRight();
console.log('usage: node foo.js [OPTIONS]\n'
+ 'options:\n'
+ help);
process.exit(0);
}
// ...
```
Some example output from this script (foo.js):
```
$ node foo.js -h
# opts: { help: true,
_order: [ { name: 'help', value: true, from: 'argv' } ],
_args: [] }
# args: []
usage: node foo.js [OPTIONS]
options:
--version Print tool version and exit.
-h, --help Print this help and exit.
-v, --verbose Verbose output. Use multiple times for more verbose.
-f FILE, --file=FILE File to process
$ node foo.js -v
# opts: { verbose: [ true ],
_order: [ { name: 'verbose', value: true, from: 'argv' } ],
_args: [] }
# args: []
$ node foo.js --version arg1
# opts: { version: true,
_order: [ { name: 'version', value: true, from: 'argv' } ],
_args: [ 'arg1' ] }
# args: [ 'arg1' ]
$ node foo.js -f bar.txt
# opts: { file: 'bar.txt',
_order: [ { name: 'file', value: 'bar.txt', from: 'argv' } ],
_args: [] }
# args: []
$ node foo.js -vvv --file=blah
# opts: { verbose: [ true, true, true ],
file: 'blah',
_order:
[ { name: 'verbose', value: true, from: 'argv' },
{ name: 'verbose', value: true, from: 'argv' },
{ name: 'verbose', value: true, from: 'argv' },
{ name: 'file', value: 'blah', from: 'argv' } ],
_args: [] }
# args: []
```
See the ["examples"](examples/) dir for a number of starter examples using
some of dashdash's features.
# Environment variable integration
If you want to allow environment variables to specify options to your tool,
dashdash makes this easy. We can change the 'verbose' option in the example
above to include an 'env' field:
```javascript
{
names: ['verbose', 'v'],
type: 'arrayOfBool',
env: 'FOO_VERBOSE', // <--- add this line
help: 'Verbose output. Use multiple times for more verbose.'
},
```
then the **"FOO_VERBOSE" environment variable** can be used to set this
option:
```shell
$ FOO_VERBOSE=1 node foo.js
# opts: { verbose: [ true ],
_order: [ { name: 'verbose', value: true, from: 'env' } ],
_args: [] }
# args: []
```
Boolean options will interpret the empty string as unset, '0' as false
and anything else as true.
```shell
$ FOO_VERBOSE= node examples/foo.js # not set
# opts: { _order: [], _args: [] }
# args: []
$ FOO_VERBOSE=0 node examples/foo.js # '0' is false
# opts: { verbose: [ false ],
_order: [ { key: 'verbose', value: false, from: 'env' } ],
_args: [] }
# args: []
$ FOO_VERBOSE=1 node examples/foo.js # true
# opts: { verbose: [ true ],
_order: [ { key: 'verbose', value: true, from: 'env' } ],
_args: [] }
# args: []
$ FOO_VERBOSE=boogabooga node examples/foo.js # true
# opts: { verbose: [ true ],
_order: [ { key: 'verbose', value: true, from: 'env' } ],
_args: [] }
# args: []
```
Non-booleans can be used as well. Strings:
```shell
$ FOO_FILE=data.txt node examples/foo.js
# opts: { file: 'data.txt',
_order: [ { key: 'file', value: 'data.txt', from: 'env' } ],
_args: [] }
# args: []
```
Numbers:
```shell
$ FOO_TIMEOUT=5000 node examples/foo.js
# opts: { timeout: 5000,
_order: [ { key: 'timeout', value: 5000, from: 'env' } ],
_args: [] }
# args: []
$ FOO_TIMEOUT=blarg node examples/foo.js
foo: error: arg for "FOO_TIMEOUT" is not a positive integer: "blarg"
```
With the `includeEnv: true` config to `parser.help()` the environment
variable can also be included in **help output**:
usage: node foo.js [OPTIONS]
options:
--version Print tool version and exit.
-h, --help Print this help and exit.
-v, --verbose Verbose output. Use multiple times for more verbose.
Environment: FOO_VERBOSE=1
-f FILE, --file=FILE File to process
# Parser config
Parser construction (i.e. `dashdash.createParser(CONFIG)`) takes the
following fields:
- `options` (Array of option specs). Required. See the
[Option specs](#option-specs) section below.
- `interspersed` (Boolean). Optional. Default is true. If true this allows
interspersed arguments and options. I.e.:
node ./tool.js -v arg1 arg2 -h # '-h' is after interspersed args
Set it to false to have '-h' **not** get parsed as an option in the above
example.
- `allowUnknown` (Boolean). Optional. Default is false. If false, this causes
unknown arguments to throw an error. I.e.:
node ./tool.js -v arg1 --afe8asefksjefhas
Set it to true to treat the unknown option as a positional
argument.
**Caveat**: When a shortopt group, such as `-xaz` contains a mix of
known and unknown options, the *entire* group is passed through
unmolested as a positional argument.
Consider if you have a known short option `-a`, and parse the
following command line:
node ./tool.js -xaz
where `-x` and `-z` are unknown. There are multiple ways to
interpret this:
1. `-x` takes a value: `{x: 'az'}`
2. `-x` and `-z` are both booleans: `{x:true,a:true,z:true}`
Since dashdash does not know what `-x` and `-z` are, it can't know
if you'd prefer to receive `{a:true,_args:['-x','-z']}` or
`{x:'az'}`, or `{_args:['-xaz']}`. Leaving the positional arg unprocessed
is the easiest mistake for the user to recover from.
# Option specs
Example using all fields:
```javascript
{
names: ['file', 'f'], // Required (or `name`).
type: 'string', // Required.
env: 'MYTOOL_FILE',
help: 'Config file to load before running "mytool"',
helpArg: 'PATH',
helpWrap: false,
default: path.resolve(process.env.HOME, '.mytoolrc')
}
```
Each option spec in the `options` array must/can have the following fields:
- `name` (String) or `names` (Array). Required. These give the option name
and aliases. The first name (if more than one given) is the key for the
parsed `opts` object.
- `type` (String). Required. One of:
- bool
- string
- number
- integer
- positiveInteger
- date (epoch seconds, e.g. 1396031701, or ISO 8601 format
`YYYY-MM-DD[THH:MM:SS[.sss][Z]]`, e.g. "2014-03-28T18:35:01.489Z")
- arrayOfBool
- arrayOfString
- arrayOfNumber
- arrayOfInteger
- arrayOfPositiveInteger
- arrayOfDate
FWIW, these names attempt to match with asserts on
[assert-plus](https://github.com/mcavage/node-assert-plus).
You can add your own custom option types with `dashdash.addOptionType`.
See below.
- `env` (String or Array of String). Optional. An environment variable name
(or names) that can be used as a fallback for this option. For example,
given a "foo.js" like this:
var options = [{names: ['dry-run', 'n'], env: 'FOO_DRY_RUN'}];
var opts = dashdash.parse({options: options});
Both `node foo.js --dry-run` and `FOO_DRY_RUN=1 node foo.js` would result
in `opts.dry_run = true`.
An environment variable is only used as a fallback, i.e. it is ignored if
the associated option is given in `argv`.
- `help` (String). Optional. Used for `parser.help()` output.
- `helpArg` (String). Optional. Used in help output as the placeholder for
the option argument, e.g. the "PATH" in:
...
-f PATH, --file=PATH File to process
...
- `helpWrap` (Boolean). Optional, default true. Set this to `false` to have
that option's `help` *not* be text wrapped in `<parser>.help()` output.
- `default`. Optional. A default value used for this option, if the
option isn't specified in argv.
- `hidden` (Boolean). Optional, default false. If true, help output will not
include this option.
# Option group headings
You can add headings between option specs in the `options` array. To do so,
simply add an object with only a `group` property -- the string to print as
the heading for the subsequent options in the array. For example:
```javascript
var options = [
{
group: 'Armament Options'
},
{
names: [ 'weapon', 'w' ],
type: 'string'
},
{
group: 'General Options'
},
{
names: [ 'help', 'h' ],
type: 'bool'
}
];
...
```
Note: You can use an empty string, `{group: ''}`, to get a blank line in help
output between groups of options.
# Help config
The `parser.help(...)` function is configurable as follows:
Options:
Armament Options:
^^ -w WEAPON, --weapon=WEAPON Weapon with which to crush. One of: |
/ sword, spear, maul |
/ General Options: |
/ -h, --help Print this help and exit. |
/ ^^^^ ^ |
\ `-- indent `-- helpCol maxCol ---'
`-- headingIndent
- `indent` (Number or String). Default 4. Set to a number (for that many
spaces) or a string for the literal indent.
- `headingIndent` (Number or String). Default half length of `indent`. Set to
a number (for that many spaces) or a string for the literal indent. This
indent applies to group heading lines, between normal option lines.
- `nameSort` (String). Default is 'length'. By default the names are
sorted to put the short opts first (i.e. '-h, --help' preferred
to '--help, -h'). Set to 'none' to not do this sorting.
- `maxCol` (Number). Default 80. Note that reflow is just done on whitespace
so a long token in the option help can overflow maxCol.
- `helpCol` (Number). If not set a reasonable value will be determined
between `minHelpCol` and `maxHelpCol`.
- `minHelpCol` (Number). Default 20.
- `maxHelpCol` (Number). Default 40.
- `helpWrap` (Boolean). Default true. Set to `false` to have option `help`
strings *not* be textwrapped to the helpCol..maxCol range.
- `includeEnv` (Boolean). Default false. If the option has associated
environment variables (via the `env` option spec attribute), then
append mentioned of those envvars to the help string.
- `includeDefault` (Boolean). Default false. If the option has a default value
(via the `default` option spec attribute, or a default on the option's type),
then a "Default: VALUE" string will be appended to the help string.
# Custom option types
Dashdash includes a good starter set of option types that it will parse for
you. However, you can add your own via:
var dashdash = require('dashdash');
dashdash.addOptionType({
name: '...',
takesArg: true,
helpArg: '...',
parseArg: function (option, optstr, arg) {
...
},
array: false, // optional
arrayFlatten: false, // optional
default: ... // optional
});
For example, a simple option type that accepts 'yes', 'y', 'no' or 'n' as
a boolean argument would look like:
var dashdash = require('dashdash');
function parseYesNo(option, optstr, arg) {
var argLower = arg.toLowerCase()
if (~['yes', 'y'].indexOf(argLower)) {
return true;
} else if (~['no', 'n'].indexOf(argLower)) {
return false;
} else {
throw new Error(format(
'arg for "%s" is not "yes" or "no": "%s"',
optstr, arg));
}
}
dashdash.addOptionType({
name: 'yesno'
takesArg: true,
helpArg: '<yes|no>',
parseArg: parseYesNo
});
var options = {
{names: ['answer', 'a'], type: 'yesno'}
};
var opts = dashdash.parse({options: options});
See "examples/custom-option-\*.js" for other examples.
See the `addOptionType` block comment in "lib/dashdash.js" for more details.
Please let me know [on twitter](https://twitter.com/trentmick)
or [with an issue](https://github.com/trentm/node-dashdash/issues/new) if you
write a generally useful one.
# Why
Why another node.js option parsing lib?
- `nopt` really is just for "tools like npm". Implicit opts (e.g. '--no-foo'
works for every '--foo'). Can't disable abbreviated opts. Can't do multiple
usages of same opt, e.g. '-vvv' (I think). Can't do grouped short opts.
- `optimist` has surprise interpretation of options (at least to me).
Implicit opts mean ambiguities and poor error handling for fat-fingering.
`process.exit` calls makes it hard to use as a libary.
- `optparse` Incomplete docs. Is this an attempted clone of Python's `optparse`.
Not clear. Some divergence. `parser.on("name", ...)` API is weird.
- `argparse` Dep on underscore. No thanks just for option processing.
`find lib | wc -l` -> `26`. Overkill.
Argparse is a bit different anyway. Not sure I want that.
- `posix-getopt` No type validation. Though that isn't a killer. AFAIK can't
have a long opt without a short alias. I.e. no `getopt_long` semantics.
Also, no whizbang features like generated help output.
- ["commander.js"](https://github.com/visionmedia/commander.js): I wrote
[a critique](http://trentm.com/2014/01/a-critique-of-commander-for-nodejs.html)
a while back. It seems fine, but last I checked had
[an outstanding bug](https://github.com/visionmedia/commander.js/pull/121)
that would prevent me from using it.
# License
MIT. See LICENSE.txt.

822
node_modules/dashdash/lib/dashdash.js generated vendored Normal file
View File

@@ -0,0 +1,822 @@
/**
* dashdash - A light, featureful and explicit option parsing library for
* node.js.
*/
// vim: set ts=4 sts=4 sw=4 et:
var p = console.log;
var format = require('util').format;
var assert = require('assert-plus');
var DEBUG = true;
if (DEBUG) {
var debug = console.warn;
} else {
var debug = function () {};
}
// ---- internal support stuff
/**
* Return a shallow copy of the given object;
*/
function shallowCopy(obj) {
if (!obj) {
return (obj);
}
var copy = {};
Object.keys(obj).forEach(function (k) {
copy[k] = obj[k];
});
return (copy);
}
function space(n) {
var s = '';
for (var i = 0; i < n; i++) {
s += ' ';
}
return s;
}
function makeIndent(arg, deflen, name) {
if (arg === null || arg === undefined)
return space(deflen);
else if (typeof (arg) === 'number')
return space(arg);
else if (typeof (arg) === 'string')
return arg;
else
assert.fail('invalid "' + name + '": not a string or number: ' + arg);
}
/**
* Return an array of lines wrapping the given text to the given width.
* This splits on whitespace. Single tokens longer than `width` are not
* broken up.
*/
function textwrap(s, width) {
var words = s.trim().split(/\s+/);
var lines = [];
var line = '';
words.forEach(function (w) {
var newLength = line.length + w.length;
if (line.length > 0)
newLength += 1;
if (newLength > width) {
lines.push(line);
line = '';
}
if (line.length > 0)
line += ' ';
line += w;
});
lines.push(line);
return lines;
}
/**
* Transform an option name to a "key" that is used as the field
* on the `opts` object returned from `<parser>.parse()`.
*
* Transformations:
* - '-' -> '_': This allow one to use hyphen in option names (common)
* but not have to do silly things like `opt["dry-run"]` to access the
* parsed results.
*/
function optionKeyFromName(name) {
return name.replace(/-/g, '_');
}
// ---- Option types
function parseBool(option, optstr, arg) {
return Boolean(arg);
}
function parseString(option, optstr, arg) {
assert.string(arg, 'arg');
return arg;
}
function parseNumber(option, optstr, arg) {
assert.string(arg, 'arg');
var num = Number(arg);
if (isNaN(num)) {
throw new Error(format('arg for "%s" is not a number: "%s"',
optstr, arg));
}
return num;
}
function parseInteger(option, optstr, arg) {
assert.string(arg, 'arg');
var num = Number(arg);
if (!/^[0-9-]+$/.test(arg) || isNaN(num)) {
throw new Error(format('arg for "%s" is not an integer: "%s"',
optstr, arg));
}
return num;
}
function parsePositiveInteger(option, optstr, arg) {
assert.string(arg, 'arg');
var num = Number(arg);
if (!/^[0-9]+$/.test(arg) || isNaN(num)) {
throw new Error(format('arg for "%s" is not a positive integer: "%s"',
optstr, arg));
}
return num;
}
/**
* Supported date args:
* - epoch second times (e.g. 1396031701)
* - ISO 8601 format: YYYY-MM-DD[THH:MM:SS[.sss][Z]]
* 2014-03-28T18:35:01.489Z
* 2014-03-28T18:35:01.489
* 2014-03-28T18:35:01Z
* 2014-03-28T18:35:01
* 2014-03-28
*/
function parseDate(option, optstr, arg) {
assert.string(arg, 'arg');
var date;
if (/^\d+$/.test(arg)) {
// epoch seconds
date = new Date(Number(arg) * 1000);
/* JSSTYLED */
} else if (/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d+)?Z?)?$/i.test(arg)) {
// ISO 8601 format
date = new Date(arg);
} else {
throw new Error(format('arg for "%s" is not a valid date format: "%s"',
optstr, arg));
}
if (date.toString() === 'Invalid Date') {
throw new Error(format('arg for "%s" is an invalid date: "%s"',
optstr, arg));
}
return date;
}
var optionTypes = {
bool: {
takesArg: false,
parseArg: parseBool
},
string: {
takesArg: true,
helpArg: 'ARG',
parseArg: parseString
},
number: {
takesArg: true,
helpArg: 'NUM',
parseArg: parseNumber
},
integer: {
takesArg: true,
helpArg: 'INT',
parseArg: parseInteger
},
positiveInteger: {
takesArg: true,
helpArg: 'INT',
parseArg: parsePositiveInteger
},
date: {
takesArg: true,
helpArg: 'DATE',
parseArg: parseDate
},
arrayOfBool: {
takesArg: false,
array: true,
parseArg: parseBool
},
arrayOfString: {
takesArg: true,
helpArg: 'ARG',
array: true,
parseArg: parseString
},
arrayOfNumber: {
takesArg: true,
helpArg: 'NUM',
array: true,
parseArg: parseNumber
},
arrayOfInteger: {
takesArg: true,
helpArg: 'INT',
array: true,
parseArg: parseInteger
},
arrayOfPositiveInteger: {
takesArg: true,
helpArg: 'INT',
array: true,
parseArg: parsePositiveInteger
},
arrayOfDate: {
takesArg: true,
helpArg: 'INT',
array: true,
parseArg: parseDate
},
};
// ---- Parser
/**
* Parser constructor.
*
* @param config {Object} The parser configuration
* - options {Array} Array of option specs. See the README for how to
* specify each option spec.
* - allowUnknown {Boolean} Default false. Whether to throw on unknown
* options. If false, then unknown args are included in the _args array.
* - interspersed {Boolean} Default true. Whether to allow interspersed
* arguments (non-options) and options. E.g.:
* node tool.js arg1 arg2 -v
* '-v' is after some args here. If `interspersed: false` then '-v'
* would not be parsed out. Note that regardless of `interspersed`
* the presence of '--' will stop option parsing, as all good
* option parsers should.
*/
function Parser(config) {
assert.object(config, 'config');
assert.arrayOfObject(config.options, 'config.options');
assert.optionalBool(config.interspersed, 'config.interspersed');
var self = this;
// Allow interspersed arguments (true by default).
this.interspersed = (config.interspersed !== undefined
? config.interspersed : true);
// Don't allow unknown flags (true by default).
this.allowUnknown = (config.allowUnknown !== undefined
? config.allowUnknown : false);
this.options = config.options.map(function (o) { return shallowCopy(o); });
this.optionFromName = {};
this.optionFromEnv = {};
for (var i = 0; i < this.options.length; i++) {
var o = this.options[i];
if (o.group !== undefined && o.group !== null) {
assert.optionalString(o.group,
format('config.options.%d.group', i));
continue;
}
assert.ok(optionTypes[o.type],
format('invalid config.options.%d.type: "%s" in %j',
i, o.type, o));
assert.optionalString(o.name, format('config.options.%d.name', i));
assert.optionalArrayOfString(o.names,
format('config.options.%d.names', i));
assert.ok((o.name || o.names) && !(o.name && o.names),
format('exactly one of "name" or "names" required: %j', o));
assert.optionalString(o.help, format('config.options.%d.help', i));
var env = o.env || [];
if (typeof (env) === 'string') {
env = [env];
}
assert.optionalArrayOfString(env, format('config.options.%d.env', i));
assert.optionalString(o.helpGroup,
format('config.options.%d.helpGroup', i));
assert.optionalBool(o.helpWrap,
format('config.options.%d.helpWrap', i));
assert.optionalBool(o.hidden, format('config.options.%d.hidden', i));
if (o.name) {
o.names = [o.name];
} else {
assert.string(o.names[0],
format('config.options.%d.names is empty', i));
}
o.key = optionKeyFromName(o.names[0]);
o.names.forEach(function (n) {
if (self.optionFromName[n]) {
throw new Error(format(
'option name collision: "%s" used in %j and %j',
n, self.optionFromName[n], o));
}
self.optionFromName[n] = o;
});
env.forEach(function (n) {
if (self.optionFromEnv[n]) {
throw new Error(format(
'option env collision: "%s" used in %j and %j',
n, self.optionFromEnv[n], o));
}
self.optionFromEnv[n] = o;
});
}
}
Parser.prototype.optionTakesArg = function optionTakesArg(option) {
return optionTypes[option.type].takesArg;
};
/**
* Parse options from the given argv.
*
* @param inputs {Object} Optional.
* - argv {Array} Optional. The argv to parse. Defaults to
* `process.argv`.
* - slice {Number} The index into argv at which options/args begin.
* Default is 2, as appropriate for `process.argv`.
* - env {Object} Optional. The env to use for 'env' entries in the
* option specs. Defaults to `process.env`.
* @returns {Object} Parsed `opts`. It has special keys `_args` (the
* remaining args from `argv`) and `_order` (gives the order that
* options were specified).
*/
Parser.prototype.parse = function parse(inputs) {
var self = this;
// Old API was `parse([argv, [slice]])`
if (Array.isArray(arguments[0])) {
inputs = {argv: arguments[0], slice: arguments[1]};
}
assert.optionalObject(inputs, 'inputs');
if (!inputs) {
inputs = {};
}
assert.optionalArrayOfString(inputs.argv, 'inputs.argv');
//assert.optionalNumber(slice, 'slice');
var argv = inputs.argv || process.argv;
var slice = inputs.slice !== undefined ? inputs.slice : 2;
var args = argv.slice(slice);
var env = inputs.env || process.env;
var opts = {};
var _order = [];
function addOpt(option, optstr, key, val, from) {
var type = optionTypes[option.type];
var parsedVal = type.parseArg(option, optstr, val);
if (type.array) {
if (!opts[key]) {
opts[key] = [];
}
if (type.arrayFlatten && Array.isArray(parsedVal)) {
for (var i = 0; i < parsedVal.length; i++) {
opts[key].push(parsedVal[i]);
}
} else {
opts[key].push(parsedVal);
}
} else {
opts[key] = parsedVal;
}
var item = { key: key, value: parsedVal, from: from };
_order.push(item);
}
// Parse args.
var _args = [];
var i = 0;
outer: while (i < args.length) {
var arg = args[i];
// End of options marker.
if (arg === '--') {
i++;
break;
// Long option
} else if (arg.slice(0, 2) === '--') {
var name = arg.slice(2);
var val = null;
var idx = name.indexOf('=');
if (idx !== -1) {
val = name.slice(idx + 1);
name = name.slice(0, idx);
}
var option = this.optionFromName[name];
if (!option) {
if (!this.allowUnknown)
throw new Error(format('unknown option: "--%s"', name));
else if (this.interspersed)
_args.push(arg);
else
break outer;
} else {
var takesArg = this.optionTakesArg(option);
if (val !== null && !takesArg) {
throw new Error(format('argument given to "--%s" option '
+ 'that does not take one: "%s"', name, arg));
}
if (!takesArg) {
addOpt(option, '--'+name, option.key, true, 'argv');
} else if (val !== null) {
addOpt(option, '--'+name, option.key, val, 'argv');
} else if (i + 1 >= args.length) {
throw new Error(format('do not have enough args for "--%s" '
+ 'option', name));
} else {
addOpt(option, '--'+name, option.key, args[i + 1], 'argv');
i++;
}
}
// Short option
} else if (arg[0] === '-' && arg.length > 1) {
var j = 1;
var allFound = true;
while (j < arg.length) {
var name = arg[j];
var option = this.optionFromName[name];
if (!option) {
allFound = false;
if (this.allowUnknown) {
if (this.interspersed) {
_args.push(arg);
break;
} else
break outer;
} else if (arg.length > 2) {
throw new Error(format(
'unknown option: "-%s" in "%s" group',
name, arg));
} else {
throw new Error(format('unknown option: "-%s"', name));
}
} else if (this.optionTakesArg(option)) {
break;
}
j++;
}
j = 1;
while (allFound && j < arg.length) {
var name = arg[j];
var val = arg.slice(j + 1); // option val if it takes an arg
var option = this.optionFromName[name];
var takesArg = this.optionTakesArg(option);
if (!takesArg) {
addOpt(option, '-'+name, option.key, true, 'argv');
} else if (val) {
addOpt(option, '-'+name, option.key, val, 'argv');
break;
} else {
if (i + 1 >= args.length) {
throw new Error(format('do not have enough args '
+ 'for "-%s" option', name));
}
addOpt(option, '-'+name, option.key, args[i + 1], 'argv');
i++;
break;
}
j++;
}
// An interspersed arg
} else if (this.interspersed) {
_args.push(arg);
// An arg and interspersed args are not allowed, so done options.
} else {
break outer;
}
i++;
}
_args = _args.concat(args.slice(i));
// Parse environment.
Object.keys(this.optionFromEnv).forEach(function (envname) {
var val = env[envname];
if (val === undefined)
return;
var option = self.optionFromEnv[envname];
if (opts[option.key] !== undefined)
return;
var takesArg = self.optionTakesArg(option);
if (takesArg) {
addOpt(option, envname, option.key, val, 'env');
} else if (val !== '') {
// Boolean envvar handling:
// - VAR=<empty-string> not set (as if the VAR was not set)
// - VAR=0 false
// - anything else true
addOpt(option, envname, option.key, (val !== '0'), 'env');
}
});
// Apply default values.
this.options.forEach(function (o) {
if (opts[o.key] === undefined) {
if (o.default !== undefined) {
opts[o.key] = o.default;
} else if (o.type && optionTypes[o.type].default !== undefined) {
opts[o.key] = optionTypes[o.type].default;
}
}
});
opts._order = _order;
opts._args = _args;
return opts;
};
/**
* Return help output for the current options.
*
* E.g.: if the current options are:
* [{names: ['help', 'h'], type: 'bool', help: 'Show help and exit.'}]
* then this would return:
* ' -h, --help Show help and exit.\n'
*
* @param config {Object} Config for controlling the option help output.
* - indent {Number|String} Default 4. An indent/prefix to use for
* each option line.
* - nameSort {String} Default is 'length'. By default the names are
* sorted to put the short opts first (i.e. '-h, --help' preferred
* to '--help, -h'). Set to 'none' to not do this sorting.
* - maxCol {Number} Default 80. Note that long tokens in a help string
* can go past this.
* - helpCol {Number} Set to specify a specific column at which
* option help will be aligned. By default this is determined
* automatically.
* - minHelpCol {Number} Default 20.
* - maxHelpCol {Number} Default 40.
* - includeEnv {Boolean} Default false. If true, a note stating the `env`
* envvar (if specified for this option) will be appended to the help
* output.
* - includeDefault {Boolean} Default false. If true, a note stating
* the `default` for this option, if any, will be appended to the help
* output.
* - helpWrap {Boolean} Default true. Wrap help text in helpCol..maxCol
* bounds.
* @returns {String}
*/
Parser.prototype.help = function help(config) {
config = config || {};
assert.object(config, 'config');
var indent = makeIndent(config.indent, 4, 'config.indent');
var headingIndent = makeIndent(config.headingIndent,
Math.round(indent.length / 2), 'config.headingIndent');
assert.optionalString(config.nameSort, 'config.nameSort');
var nameSort = config.nameSort || 'length';
assert.ok(~['length', 'none'].indexOf(nameSort),
'invalid "config.nameSort"');
assert.optionalNumber(config.maxCol, 'config.maxCol');
assert.optionalNumber(config.maxHelpCol, 'config.maxHelpCol');
assert.optionalNumber(config.minHelpCol, 'config.minHelpCol');
assert.optionalNumber(config.helpCol, 'config.helpCol');
assert.optionalBool(config.includeEnv, 'config.includeEnv');
assert.optionalBool(config.includeDefault, 'config.includeDefault');
assert.optionalBool(config.helpWrap, 'config.helpWrap');
var maxCol = config.maxCol || 80;
var minHelpCol = config.minHelpCol || 20;
var maxHelpCol = config.maxHelpCol || 40;
var lines = [];
var maxWidth = 0;
this.options.forEach(function (o) {
if (o.hidden) {
return;
}
if (o.group !== undefined && o.group !== null) {
// We deal with groups in the next pass
lines.push(null);
return;
}
var type = optionTypes[o.type];
var arg = o.helpArg || type.helpArg || 'ARG';
var line = '';
var names = o.names.slice();
if (nameSort === 'length') {
names.sort(function (a, b) {
if (a.length < b.length)
return -1;
else if (b.length < a.length)
return 1;
else
return 0;
})
}
names.forEach(function (name, i) {
if (i > 0)
line += ', ';
if (name.length === 1) {
line += '-' + name
if (type.takesArg)
line += ' ' + arg;
} else {
line += '--' + name
if (type.takesArg)
line += '=' + arg;
}
});
maxWidth = Math.max(maxWidth, line.length);
lines.push(line);
});
// Add help strings.
var helpCol = config.helpCol;
if (!helpCol) {
helpCol = maxWidth + indent.length + 2;
helpCol = Math.min(Math.max(helpCol, minHelpCol), maxHelpCol);
}
var i = -1;
this.options.forEach(function (o) {
if (o.hidden) {
return;
}
i++;
if (o.group !== undefined && o.group !== null) {
if (o.group === '') {
// Support a empty string "group" to have a blank line between
// sets of options.
lines[i] = '';
} else {
// Render the group heading with the heading-specific indent.
lines[i] = (i === 0 ? '' : '\n') + headingIndent +
o.group + ':';
}
return;
}
var helpDefault;
if (config.includeDefault) {
if (o.default !== undefined) {
helpDefault = format('Default: %j', o.default);
} else if (o.type && optionTypes[o.type].default !== undefined) {
helpDefault = format('Default: %j',
optionTypes[o.type].default);
}
}
var line = lines[i] = indent + lines[i];
if (!o.help && !(config.includeEnv && o.env) && !helpDefault) {
return;
}
var n = helpCol - line.length;
if (n >= 0) {
line += space(n);
} else {
line += '\n' + space(helpCol);
}
var helpEnv = '';
if (o.env && o.env.length && config.includeEnv) {
helpEnv += 'Environment: ';
var type = optionTypes[o.type];
var arg = o.helpArg || type.helpArg || 'ARG';
var envs = (Array.isArray(o.env) ? o.env : [o.env]).map(
function (e) {
if (type.takesArg) {
return e + '=' + arg;
} else {
return e + '=1';
}
}
);
helpEnv += envs.join(', ');
}
var help = (o.help || '').trim();
if (o.helpWrap !== false && config.helpWrap !== false) {
// Wrap help description normally.
if (help.length && !~'.!?"\''.indexOf(help.slice(-1))) {
help += '.';
}
if (help.length) {
help += ' ';
}
help += helpEnv;
if (helpDefault) {
if (helpEnv) {
help += '. ';
}
help += helpDefault;
}
line += textwrap(help, maxCol - helpCol).join(
'\n' + space(helpCol));
} else {
// Do not wrap help description, but indent newlines appropriately.
var helpLines = help.split('\n').filter(
function (ln) { return ln.length });
if (helpEnv !== '') {
helpLines.push(helpEnv);
}
if (helpDefault) {
helpLines.push(helpDefault);
}
line += helpLines.join('\n' + space(helpCol));
}
lines[i] = line;
});
var rv = '';
if (lines.length > 0) {
rv = lines.join('\n') + '\n';
}
return rv;
};
// ---- exports
function createParser(config) {
return new Parser(config);
}
/**
* Parse argv with the given options.
*
* @param config {Object} A merge of all the available fields from
* `dashdash.Parser` and `dashdash.Parser.parse`: options, interspersed,
* argv, env, slice.
*/
function parse(config) {
assert.object(config, 'config');
assert.optionalArrayOfString(config.argv, 'config.argv');
assert.optionalObject(config.env, 'config.env');
var config = shallowCopy(config);
var argv = config.argv;
delete config.argv;
var env = config.env;
delete config.env;
var parser = new Parser(config);
return parser.parse({argv: argv, env: env});
}
/**
* Add a new option type.
*
* @params optionType {Object}:
* - name {String} Required.
* - takesArg {Boolean} Required. Whether this type of option takes an
* argument on process.argv. Typically this is true for all but the
* "bool" type.
* - helpArg {String} Required iff `takesArg === true`. The string to
* show in generated help for options of this type.
* - parseArg {Function} Require. `function (option, optstr, arg)` parser
* that takes a string argument and returns an instance of the
* appropriate type, or throws an error if the arg is invalid.
* - array {Boolean} Optional. Set to true if this is an 'arrayOf' type
* that collects multiple usages of the option in process.argv and
* puts results in an array.
* - arrayFlatten {Boolean} Optional. XXX
* - default Optional. Default value for options of this type, if no
* default is specified in the option type usage.
*/
function addOptionType(optionType) {
assert.object(optionType, 'optionType');
assert.string(optionType.name, 'optionType.name');
assert.bool(optionType.takesArg, 'optionType.takesArg');
if (optionType.takesArg) {
assert.string(optionType.helpArg, 'optionType.helpArg');
}
assert.func(optionType.parseArg, 'optionType.parseArg');
assert.optionalBool(optionType.array, 'optionType.array');
assert.optionalBool(optionType.arrayFlatten, 'optionType.arrayFlatten');
optionTypes[optionType.name] = {
takesArg: optionType.takesArg,
helpArg: optionType.helpArg,
parseArg: optionType.parseArg,
array: optionType.array,
arrayFlatten: optionType.arrayFlatten,
default: optionType.default
}
}
module.exports = {
createParser: createParser,
Parser: Parser,
parse: parse,
addOptionType: addOptionType,
// Export the parseFoo parsers because they might be useful as primitives
// for custom option types.
parseBool: parseBool,
parseString: parseString,
parseNumber: parseNumber,
parseInteger: parseInteger,
parsePositiveInteger: parsePositiveInteger,
parseDate: parseDate
};

106
node_modules/dashdash/package.json generated vendored Normal file
View File

@@ -0,0 +1,106 @@
{
"_args": [
[
"dashdash@>=1.10.1 <2.0.0",
"/home/mitchell/Desktop/test-mywebsite/mywebsite/node_modules/sshpk"
]
],
"_from": "dashdash@>=1.10.1 <2.0.0",
"_id": "dashdash@1.11.0",
"_inCache": true,
"_installable": true,
"_location": "/dashdash",
"_npmUser": {
"email": "trentm@gmail.com",
"name": "trentm"
},
"_npmVersion": "1.4.28",
"_phantomChildren": {},
"_requested": {
"name": "dashdash",
"raw": "dashdash@>=1.10.1 <2.0.0",
"rawSpec": ">=1.10.1 <2.0.0",
"scope": null,
"spec": ">=1.10.1 <2.0.0",
"type": "range"
},
"_requiredBy": [
"/sshpk"
],
"_resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.11.0.tgz",
"_shasum": "babd3892d71ab403948c6a2b9d65f7de1ace8e92",
"_shrinkwrap": null,
"_spec": "dashdash@>=1.10.1 <2.0.0",
"_where": "/home/mitchell/Desktop/test-mywebsite/mywebsite/node_modules/sshpk",
"author": {
"email": "trentm@gmail.com",
"name": "Trent Mick",
"url": "http://trentm.com"
},
"bugs": {
"url": "https://github.com/trentm/node-dashdash/issues"
},
"contributors": [
{
"name": "Trent Mick",
"email": "trentm@gmail.com",
"url": "http://trentm.com"
},
{
"name": "Isaac Schlueter",
"url": "https://github.com/isaacs"
},
{
"name": "Joshua M. Clulow",
"url": "https://github.com/jclulow"
},
{
"name": "Patrick Mooney",
"url": "https://github.com/pfmooney"
}
],
"dependencies": {
"assert-plus": "0.1.x"
},
"description": "A light, featureful and explicit option parsing library.",
"devDependencies": {
"nodeunit": "0.9.x"
},
"directories": {},
"dist": {
"shasum": "babd3892d71ab403948c6a2b9d65f7de1ace8e92",
"tarball": "http://registry.npmjs.org/dashdash/-/dashdash-1.11.0.tgz"
},
"engines": {
"node": ">=0.8"
},
"gitHead": "c0f126a9ec1c8e75ef904a68b1f3b4b7fc1a86ad",
"homepage": "https://github.com/trentm/node-dashdash",
"keywords": [
"args",
"cli",
"command",
"option",
"parser",
"parsing"
],
"license": "MIT",
"main": "./lib/dashdash.js",
"maintainers": [
{
"name": "trentm",
"email": "trentm@gmail.com"
}
],
"name": "dashdash",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git://github.com/trentm/node-dashdash.git"
},
"scripts": {
"test": "nodeunit test/*.test.js"
},
"version": "1.11.0"
}