argparse
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -0,1 +1,8 @@ | ||
1.0.5 / 2016-02-05 | ||
------------------ | ||
- Removed lodash dependency to significantly reduce install size. | ||
Thanks to @mourner. | ||
1.0.4 / 2016-01-17 | ||
@@ -2,0 +9,0 @@ ------------------ |
@@ -10,7 +10,8 @@ /** internal | ||
var format = require('util').format; | ||
var _ = require('lodash'); | ||
// Constants | ||
var $$ = require('./const'); | ||
var c = require('./const'); | ||
var $$ = require('./utils'); | ||
//Actions | ||
@@ -31,4 +32,2 @@ var ActionHelp = require('./action/help'); | ||
/** | ||
@@ -140,3 +139,3 @@ * new ActionContainer(options) | ||
this._actions.forEach(function (action) { | ||
if (action.dest in options) { | ||
if ($$.has(options, action.dest)) { | ||
action.defaultValue = options[action.dest]; | ||
@@ -154,6 +153,6 @@ } | ||
ActionContainer.prototype.getDefault = function (dest) { | ||
var result = (_.has(this._defaults, dest)) ? this._defaults[dest] : null; | ||
var result = $$.has(this._defaults, dest) ? this._defaults[dest] : null; | ||
this._actions.forEach(function (action) { | ||
if (action.dest === dest && _.has(action, 'defaultValue')) { | ||
if (action.dest === dest && $$.has(action, 'defaultValue')) { | ||
result = action.defaultValue; | ||
@@ -182,6 +181,6 @@ } | ||
if (!_.isArray(args)) { | ||
if (!Array.isArray(args)) { | ||
throw new TypeError('addArgument first argument should be an array'); | ||
} | ||
if (!_.isObject(options) || _.isArray(options)) { | ||
if (typeof options !== 'object' || Array.isArray(options)) { | ||
throw new TypeError('addArgument second argument should be a hash'); | ||
@@ -204,7 +203,7 @@ } | ||
// if no default was supplied, use the parser-level default | ||
if (_.isUndefined(options.defaultValue)) { | ||
if (typeof options.defaultValue === 'undefined') { | ||
var dest = options.dest; | ||
if (_.has(this._defaults, dest)) { | ||
if ($$.has(this._defaults, dest)) { | ||
options.defaultValue = this._defaults[dest]; | ||
} else if (!_.isUndefined(this.argumentDefault)) { | ||
} else if (typeof this.argumentDefault !== 'undefined') { | ||
options.defaultValue = this.argumentDefault; | ||
@@ -216,3 +215,3 @@ } | ||
var ActionClass = this._popActionClass(options); | ||
if (! _.isFunction(ActionClass)) { | ||
if (typeof ActionClass !== 'function') { | ||
throw new Error(format('Unknown action "%s".', ActionClass)); | ||
@@ -224,3 +223,3 @@ } | ||
var typeFunction = this._registryGet('type', action.type, action.type); | ||
if (!_.isFunction(typeFunction)) { | ||
if (typeof typeFunction !== 'function') { | ||
throw new Error(format('"%s" is not callable', typeFunction)); | ||
@@ -274,3 +273,3 @@ } | ||
if (optionString.match(self._regexpNegativeNumber)) { | ||
if (!_.some(self._hasNegativeNumberOptionals)) { | ||
if (!self._hasNegativeNumberOptionals.some(Boolean)) { | ||
self._hasNegativeNumberOptionals.push(true); | ||
@@ -352,4 +351,4 @@ } | ||
ActionContainer.prototype._getPositional = function (dest, options) { | ||
if (_.isArray(dest)) { | ||
dest = _.first(dest); | ||
if (Array.isArray(dest)) { | ||
dest = dest[0]; | ||
} | ||
@@ -363,6 +362,6 @@ // make sure required is not specified | ||
// always required | ||
if (options.nargs !== $$.OPTIONAL && options.nargs !== $$.ZERO_OR_MORE) { | ||
if (options.nargs !== c.OPTIONAL && options.nargs !== c.ZERO_OR_MORE) { | ||
options.required = true; | ||
} | ||
if (options.nargs === $$.ZERO_OR_MORE && options.defaultValue === undefined) { | ||
if (options.nargs === c.ZERO_OR_MORE && typeof options.defaultValue === 'undefined') { | ||
options.required = true; | ||
@@ -405,3 +404,3 @@ } | ||
var optionStringDest = optionStringsLong.length ? optionStringsLong[0] :optionStrings[0]; | ||
dest = _.trim(optionStringDest, this.prefixChars); | ||
dest = $$.trimChars(optionStringDest, this.prefixChars); | ||
@@ -435,3 +434,3 @@ if (dest.length === 0) { | ||
var handlerString = this.conflictHandler; | ||
var handlerFuncName = "_handleConflict" + _.capitalize(handlerString); | ||
var handlerFuncName = "_handleConflict" + $$.capitalize(handlerString); | ||
var func = this[handlerFuncName]; | ||
@@ -466,3 +465,3 @@ if (typeof func === 'undefined') { | ||
ActionContainer.prototype._handleConflictError = function (action, conflOptionals) { | ||
var conflicts = _.map(conflOptionals, function (pair) {return pair[0]; }); | ||
var conflicts = conflOptionals.map(function (pair) {return pair[0]; }); | ||
conflicts = conflicts.join(', '); | ||
@@ -469,0 +468,0 @@ throw argumentErrorHelper( |
@@ -35,3 +35,3 @@ /** | ||
// Constants | ||
var $$ = require('./const'); | ||
var c = require('./const'); | ||
@@ -103,5 +103,5 @@ | ||
return this.optionStrings.join('/'); | ||
} else if (this.metavar !== null && this.metavar !== $$.SUPPRESS) { | ||
} else if (this.metavar !== null && this.metavar !== c.SUPPRESS) { | ||
return this.metavar; | ||
} else if (this.dest !== undefined && this.dest !== $$.SUPPRESS) { | ||
} else if (this.dest !== undefined && this.dest !== c.SUPPRESS) { | ||
return this.dest; | ||
@@ -108,0 +108,0 @@ } |
@@ -17,3 +17,3 @@ /*:nodoc:* | ||
// Constants | ||
var $$ = require('../const'); | ||
var c = require('../const'); | ||
@@ -34,3 +34,3 @@ /*:nodoc:* | ||
} | ||
if (!!this.constant && this.nargs !== $$.OPTIONAL) { | ||
if (!!this.constant && this.nargs !== c.OPTIONAL) { | ||
throw new Error('nargs must be OPTIONAL to supply const'); | ||
@@ -52,7 +52,5 @@ } | ||
ActionAppend.prototype.call = function (parser, namespace, values) { | ||
var items = [].concat(namespace[this.dest] || []); // or _.clone | ||
var items = (namespace[this.dest] || []).slice(); | ||
items.push(values); | ||
namespace.set(this.dest, items); | ||
}; | ||
@@ -14,3 +14,3 @@ /*:nodoc:* | ||
// Constants | ||
var $$ = require('../const'); | ||
var c = require('../const'); | ||
@@ -28,5 +28,5 @@ /*:nodoc:* | ||
else { | ||
options.defaultValue = $$.SUPPRESS; | ||
options.defaultValue = c.SUPPRESS; | ||
} | ||
options.dest = (options.dest !== null ? options.dest: $$.SUPPRESS); | ||
options.dest = (options.dest !== null ? options.dest: c.SUPPRESS); | ||
options.nargs = 0; | ||
@@ -33,0 +33,0 @@ Action.call(this, options); |
@@ -16,3 +16,3 @@ /*:nodoc:* | ||
// Constants | ||
var $$ = require('../const'); | ||
var c = require('../const'); | ||
@@ -33,3 +33,3 @@ | ||
} | ||
if (this.constant !== undefined && this.nargs !== $$.OPTIONAL) { | ||
if (this.constant !== undefined && this.nargs !== c.OPTIONAL) { | ||
throw new Error('nargs must be OPTIONAL to supply const'); | ||
@@ -36,0 +36,0 @@ } |
@@ -12,3 +12,2 @@ /** internal | ||
var format = require('util').format; | ||
var _ = require('lodash'); | ||
@@ -19,3 +18,3 @@ | ||
// Constants | ||
var $$ = require('../const'); | ||
var c = require('../const'); | ||
@@ -50,4 +49,4 @@ // Errors | ||
options = options || {}; | ||
options.dest = options.dest || $$.SUPPRESS; | ||
options.nargs = $$.PARSER; | ||
options.dest = options.dest || c.SUPPRESS; | ||
options.nargs = c.PARSER; | ||
@@ -94,3 +93,3 @@ this.debug = (options.debug === true); | ||
// create a pseudo-action to hold the choice help | ||
if (!!options.help || _.isString(options.help)) { | ||
if (!!options.help || typeof options.help === 'string') { | ||
var help = options.help; | ||
@@ -133,3 +132,3 @@ delete options.help; | ||
// set the parser name if requested | ||
if (this.dest !== $$.SUPPRESS) { | ||
if (this.dest !== c.SUPPRESS) { | ||
namespace[this.dest] = parserName; | ||
@@ -145,3 +144,3 @@ } | ||
parserName, | ||
_.keys(this._nameParserMap).join(', ') | ||
Object.keys(this._nameParserMap).join(', ') | ||
)); | ||
@@ -153,3 +152,1 @@ } | ||
}; | ||
@@ -16,3 +16,3 @@ /*:nodoc:* | ||
// | ||
var $$ = require('../const'); | ||
var c = require('../const'); | ||
@@ -26,4 +26,4 @@ /*:nodoc:* | ||
options = options || {}; | ||
options.defaultValue = (!!options.defaultValue ? options.defaultValue: $$.SUPPRESS); | ||
options.dest = (options.dest || $$.SUPPRESS); | ||
options.defaultValue = (!!options.defaultValue ? options.defaultValue: c.SUPPRESS); | ||
options.dest = (options.dest || c.SUPPRESS); | ||
options.nargs = 0; | ||
@@ -50,4 +50,1 @@ this.version = options.version; | ||
}; | ||
@@ -13,9 +13,9 @@ /** | ||
var Path = require('path'); | ||
var _ = require('lodash'); | ||
var sprintf = require('sprintf-js').sprintf; | ||
// Constants | ||
var $$ = require('./const'); | ||
var c = require('./const'); | ||
var $$ = require('./utils'); | ||
var ActionContainer = require('./action_container'); | ||
@@ -117,3 +117,3 @@ | ||
action: 'help', | ||
defaultValue: $$.SUPPRESS, | ||
defaultValue: c.SUPPRESS, | ||
help: 'Show this help message and exit.' | ||
@@ -129,3 +129,3 @@ } | ||
version: this.version, | ||
defaultValue: $$.SUPPRESS, | ||
defaultValue: c.SUPPRESS, | ||
help: "Show program's version number and exit." | ||
@@ -190,3 +190,3 @@ } | ||
formatter.addUsage(this.usage, positionals, groups, ''); | ||
options.prog = _.trim(formatter.formatHelp()); | ||
options.prog = formatter.formatHelp().trim(); | ||
} | ||
@@ -272,7 +272,7 @@ | ||
self._actions.forEach(function (action) { | ||
if (action.dest !== $$.SUPPRESS) { | ||
if (!_.has(namespace, action.dest)) { | ||
if (action.defaultValue !== $$.SUPPRESS) { | ||
if (action.dest !== c.SUPPRESS) { | ||
if (!$$.has(namespace, action.dest)) { | ||
if (action.defaultValue !== c.SUPPRESS) { | ||
var defaultValue = action.defaultValue; | ||
if (_.isString(action.defaultValue)) { | ||
if (typeof action.defaultValue === 'string') { | ||
defaultValue = self._getValue(action, defaultValue); | ||
@@ -286,3 +286,3 @@ } | ||
_.keys(self._defaults).forEach(function (dest) { | ||
Object.keys(self._defaults).forEach(function (dest) { | ||
namespace[dest] = self._defaults[dest]; | ||
@@ -297,5 +297,5 @@ }); | ||
args = res[1]; | ||
if (_.has(namespace, $$._UNRECOGNIZED_ARGS_ATTR)) { | ||
args = _.union(args, namespace[$$._UNRECOGNIZED_ARGS_ATTR]); | ||
delete namespace[$$._UNRECOGNIZED_ARGS_ATTR]; | ||
if ($$.has(namespace, c._UNRECOGNIZED_ARGS_ATTR)) { | ||
args = $$.arrayUnion(args, namespace[c._UNRECOGNIZED_ARGS_ATTR]); | ||
delete namespace[c._UNRECOGNIZED_ARGS_ATTR]; | ||
} | ||
@@ -336,3 +336,3 @@ return [namespace, args]; | ||
key = actionHash(mutexAction); | ||
if (!_.has(actionConflicts, key)) { | ||
if (!$$.has(actionConflicts, key)) { | ||
actionConflicts[key] = []; | ||
@@ -403,3 +403,3 @@ } | ||
if (argumentValues !== $$.SUPPRESS) { | ||
if (argumentValues !== c.SUPPRESS) { | ||
action.call(self, namespace, argumentValues, optionString); | ||
@@ -440,3 +440,3 @@ } | ||
if (_.keys(optionalsMap).indexOf(optionString) >= 0) { | ||
if (Object.keys(optionalsMap).indexOf(optionString) >= 0) { | ||
action = optionalsMap[optionString]; | ||
@@ -446,4 +446,3 @@ explicitArg = newExplicitArg; | ||
else { | ||
var msg = 'ignored explicit argument %r'; | ||
throw argumentErrorHelper(action, msg); | ||
throw argumentErrorHelper(action, sprintf('ignored explicit argument %r', explicitArg)); | ||
} | ||
@@ -462,4 +461,3 @@ } | ||
else { | ||
var message = 'ignored explicit argument %r'; | ||
throw argumentErrorHelper(action, sprintf(message, explicitArg)); | ||
throw argumentErrorHelper(action, sprintf('ignored explicit argument %r', explicitArg)); | ||
} | ||
@@ -509,13 +507,13 @@ } | ||
// and add the Positional and its args to the list | ||
_.zip(positionals, argCounts).forEach(function (item) { | ||
var action = item[0]; | ||
var argCount = item[1]; | ||
if (argCount === undefined) { | ||
return; | ||
} | ||
var args = argStrings.slice(startIndex, startIndex + argCount); | ||
for (var i = 0; i < positionals.length; i++) { | ||
var action = positionals[i]; | ||
var argCount = argCounts[i]; | ||
if (argCount === undefined) { | ||
continue; | ||
} | ||
var args = argStrings.slice(startIndex, startIndex + argCount); | ||
startIndex += argCount; | ||
takeAction(action, args); | ||
}); | ||
startIndex += argCount; | ||
takeAction(action, args); | ||
} | ||
@@ -597,3 +595,3 @@ // slice off the Positionals that we just parsed and return the | ||
if (action.required) { | ||
if (_.indexOf(seenActions, action) < 0) { | ||
if (seenActions.indexOf(action) < 0) { | ||
self.error(format('Argument "%s" is required', action.getName())); | ||
@@ -608,4 +606,4 @@ } | ||
if (group.required) { | ||
actionUsed = _.some(group._groupActions, function (action) { | ||
return _.includes(seenNonDefaultActions, action); | ||
actionUsed = group._groupActions.some(function (action) { | ||
return seenNonDefaultActions.indexOf(action) !== -1; | ||
}); | ||
@@ -617,3 +615,3 @@ | ||
group._groupActions.forEach(function (action) { | ||
if (action.help !== $$.SUPPRESS) { | ||
if (action.help !== c.SUPPRESS) { | ||
names.push(action.getName()); | ||
@@ -682,6 +680,6 @@ } | ||
break; | ||
case $$.OPTIONAL: | ||
case c.OPTIONAL: | ||
message = 'Expected at most one argument.'; | ||
break; | ||
case $$.ONE_OR_MORE: | ||
case c.ONE_OR_MORE: | ||
message = 'Expected at least one argument.'; | ||
@@ -793,3 +791,3 @@ break; | ||
if (argString.match(this._regexpNegativeNumber)) { | ||
if (!_.some(this._hasNegativeNumberOptionals)) { | ||
if (!this._hasNegativeNumberOptionals.some(Boolean)) { | ||
return null; | ||
@@ -874,19 +872,19 @@ } | ||
// allow zero or more arguments | ||
case $$.OPTIONAL: | ||
case c.OPTIONAL: | ||
regexpNargs = '(-*A?-*)'; | ||
break; | ||
// allow zero or more arguments | ||
case $$.ZERO_OR_MORE: | ||
case c.ZERO_OR_MORE: | ||
regexpNargs = '(-*[A-]*)'; | ||
break; | ||
// allow one or more arguments | ||
case $$.ONE_OR_MORE: | ||
case c.ONE_OR_MORE: | ||
regexpNargs = '(-*A[A-]*)'; | ||
break; | ||
// allow any number of options or arguments | ||
case $$.REMAINDER: | ||
case c.REMAINDER: | ||
regexpNargs = '([-AO]*)'; | ||
break; | ||
// allow one argument followed by any number of options or arguments | ||
case $$.PARSER: | ||
case c.PARSER: | ||
regexpNargs = '(-*A[-AO]*)'; | ||
@@ -896,3 +894,3 @@ break; | ||
default: | ||
regexpNargs = '(-*' + _.repeat('-*A', action.nargs) + '-*)'; | ||
regexpNargs = '(-*' + $$.repeat('-*A', action.nargs) + '-*)'; | ||
} | ||
@@ -918,3 +916,3 @@ | ||
// for everything but PARSER args, strip out '--' | ||
if (action.nargs !== $$.PARSER && action.nargs !== $$.REMAINDER) { | ||
if (action.nargs !== c.PARSER && action.nargs !== c.REMAINDER) { | ||
argStrings = argStrings.filter(function (arrayElement) { | ||
@@ -928,3 +926,3 @@ return arrayElement !== '--'; | ||
// optional argument produces a default when not present | ||
if (argStrings.length === 0 && action.nargs === $$.OPTIONAL) { | ||
if (argStrings.length === 0 && action.nargs === c.OPTIONAL) { | ||
@@ -940,3 +938,3 @@ value = (action.isOptional()) ? action.constant: action.defaultValue; | ||
// args, use the default if it is anything other than None | ||
} else if (argStrings.length === 0 && action.nargs === $$.ZERO_OR_MORE && | ||
} else if (argStrings.length === 0 && action.nargs === c.ZERO_OR_MORE && | ||
action.optionStrings.length === 0) { | ||
@@ -949,3 +947,3 @@ | ||
} else if (argStrings.length === 1 && | ||
(!action.nargs || action.nargs === $$.OPTIONAL)) { | ||
(!action.nargs || action.nargs === c.OPTIONAL)) { | ||
@@ -957,3 +955,3 @@ argString = argStrings[0]; | ||
// REMAINDER arguments convert all values, checking none | ||
} else if (action.nargs === $$.REMAINDER) { | ||
} else if (action.nargs === c.REMAINDER) { | ||
value = argStrings.map(function (v) { | ||
@@ -964,3 +962,3 @@ return self._getValue(action, v); | ||
// PARSER arguments convert all values, but check only the first | ||
} else if (action.nargs === $$.PARSER) { | ||
} else if (action.nargs === c.PARSER) { | ||
value = argStrings.map(function (v) { | ||
@@ -989,3 +987,3 @@ return self._getValue(action, v); | ||
var typeFunction = this._registryGet('type', action.type, action.type); | ||
if (!_.isFunction(typeFunction)) { | ||
if (typeof typeFunction !== 'function') { | ||
var message = format('%s is not callable', typeFunction); | ||
@@ -1005,3 +1003,3 @@ throw argumentErrorHelper(action, message); | ||
var name = null; | ||
if (_.isString(action.type)) { | ||
if (typeof action.type === 'string') { | ||
name = action.type; | ||
@@ -1024,3 +1022,3 @@ } else { | ||
// choise for argument can by array or string | ||
if ((_.isString(choices) || _.isArray(choices)) && | ||
if ((typeof choices === 'string' || Array.isArray(choices)) && | ||
choices.indexOf(value) !== -1) { | ||
@@ -1030,14 +1028,14 @@ return; | ||
// choise for subparsers can by only hash | ||
if (_.isObject(choices) && !_.isArray(choices) && choices[value]) { | ||
if (typeof choices === 'object' && !Array.isArray(choices) && choices[value]) { | ||
return; | ||
} | ||
if (_.isString(choices)) { | ||
if (typeof choices === 'string') { | ||
choices = choices.split('').join(', '); | ||
} | ||
else if (_.isArray(choices)) { | ||
else if (Array.isArray(choices)) { | ||
choices = choices.join(', '); | ||
} | ||
else { | ||
choices = _.keys(choices).join(', '); | ||
choices = Object.keys(choices).join(', '); | ||
} | ||
@@ -1191,3 +1189,3 @@ var message = format('Invalid choice: %s (choose from [%s])', value, choices); | ||
} | ||
var msg = format('%s: error: %s', this.prog, message) + $$.EOL; | ||
var msg = format('%s: error: %s', this.prog, message) + c.EOL; | ||
@@ -1194,0 +1192,0 @@ if (this.debug === true) { |
'use strict'; | ||
var util = require('util'); | ||
var _ = require('lodash'); | ||
// Constants | ||
var $$ = require('../const'); | ||
var c = require('../const'); | ||
var $$ = require('../utils'); | ||
var HelpFormatter = require('./formatter.js'); | ||
@@ -31,4 +30,4 @@ | ||
if (action.help.indexOf('%(defaultValue)s') === -1) { | ||
if (action.defaultValue !== $$.SUPPRESS) { | ||
var defaulting_nargs = [$$.OPTIONAL, $$.ZERO_OR_MORE]; | ||
if (action.defaultValue !== c.SUPPRESS) { | ||
var defaulting_nargs = [c.OPTIONAL, c.ZERO_OR_MORE]; | ||
if (action.isOptional() || (defaulting_nargs.indexOf(action.nargs) >= 0)) { | ||
@@ -63,3 +62,3 @@ help += ' (default: %(defaultValue)s)'; | ||
lines = lines.map(function (line) { | ||
return _.trimEnd(indent + line); | ||
return $$.trimEnd(indent + line); | ||
}); | ||
@@ -66,0 +65,0 @@ return lines.join('\n'); |
@@ -16,9 +16,10 @@ /** | ||
var _ = require('lodash'); | ||
var sprintf = require('sprintf-js').sprintf; | ||
// Constants | ||
var $$ = require('../const'); | ||
var c = require('../const'); | ||
var $$ = require('../utils'); | ||
/*:nodoc:* internal | ||
@@ -82,9 +83,9 @@ * new Support(parent, heding) | ||
heading = ''; | ||
if (!!this._heading && this._heading !== $$.SUPPRESS) { | ||
if (!!this._heading && this._heading !== c.SUPPRESS) { | ||
var currentIndent = formatter.currentIndent; | ||
heading = _.repeat(' ', currentIndent) + this._heading + ':' + $$.EOL; | ||
heading = $$.repeat(' ', currentIndent) + this._heading + ':' + c.EOL; | ||
} | ||
// join the section-initialize newline, the heading and the help | ||
return formatter._joinParts([$$.EOL, heading, itemHelp, $$.EOL]); | ||
return formatter._joinParts([c.EOL, heading, itemHelp, c.EOL]); | ||
}; | ||
@@ -119,3 +120,3 @@ | ||
this._whitespaceMatcher = new RegExp('\\s+', 'g'); | ||
this._longBreakMatcher = new RegExp($$.EOL + $$.EOL + $$.EOL + '+', 'g'); | ||
this._longBreakMatcher = new RegExp(c.EOL + c.EOL + c.EOL + '+', 'g'); | ||
}; | ||
@@ -200,3 +201,3 @@ | ||
HelpFormatter.prototype.addText = function (text) { | ||
if (!!text && text !== $$.SUPPRESS) { | ||
if (!!text && text !== c.SUPPRESS) { | ||
this._addItem(this._formatText, [text]); | ||
@@ -222,3 +223,3 @@ } | ||
HelpFormatter.prototype.addUsage = function (usage, actions, groups, prefix) { | ||
if (usage !== $$.SUPPRESS) { | ||
if (usage !== c.SUPPRESS) { | ||
this._addItem(this._formatUsage, [usage, actions, groups, prefix]); | ||
@@ -237,3 +238,3 @@ } | ||
HelpFormatter.prototype.addArgument = function (action) { | ||
if (action.help !== $$.SUPPRESS) { | ||
if (action.help !== c.SUPPRESS) { | ||
var self = this; | ||
@@ -307,4 +308,4 @@ | ||
if (help) { | ||
help = help.replace(this._longBreakMatcher, $$.EOL + $$.EOL); | ||
help = _.trim(help, $$.EOL) + $$.EOL; | ||
help = help.replace(this._longBreakMatcher, c.EOL + c.EOL); | ||
help = $$.trimChars(help, c.EOL) + c.EOL; | ||
} | ||
@@ -316,3 +317,3 @@ return help; | ||
return partStrings.filter(function (part) { | ||
return (!!part && part !== $$.SUPPRESS); | ||
return (!!part && part !== c.SUPPRESS); | ||
}).join(''); | ||
@@ -322,3 +323,3 @@ }; | ||
HelpFormatter.prototype._formatUsage = function (usage, actions, groups, prefix) { | ||
if (!prefix && !_.isString(prefix)) { | ||
if (!prefix && typeof prefix !== 'string') { | ||
prefix = 'usage: '; | ||
@@ -409,3 +410,3 @@ } | ||
if (prefix.length + prog.length <= 0.75 * textWidth) { | ||
indent = _.repeat(' ', (prefix.length + prog.length + 1)); | ||
indent = $$.repeat(' ', (prefix.length + prog.length + 1)); | ||
if (optionalParts) { | ||
@@ -424,3 +425,3 @@ lines = [].concat( | ||
} else { | ||
indent = _.repeat(' ', prefix.length); | ||
indent = $$.repeat(' ', prefix.length); | ||
parts = optionalParts + positionalParts; | ||
@@ -437,3 +438,3 @@ lines = _getLines(parts, indent); | ||
// join lines into usage | ||
usage = lines.join($$.EOL); | ||
usage = lines.join(c.EOL); | ||
} | ||
@@ -443,3 +444,3 @@ } | ||
// prefix with 'usage:' | ||
return prefix + usage + $$.EOL + $$.EOL; | ||
return prefix + usage + c.EOL + c.EOL; | ||
}; | ||
@@ -462,3 +463,3 @@ | ||
//if (actions.slice(start, end) === group._groupActions) { | ||
if (_.isEqual(actions.slice(start, end), group._groupActions)) { | ||
if ($$.arrayEqual(actions.slice(start, end), group._groupActions)) { | ||
group._groupActions.forEach(function (action) { | ||
@@ -503,3 +504,3 @@ groupActions.push(action); | ||
// remove | separators for suppressed arguments | ||
if (action.help === $$.SUPPRESS) { | ||
if (action.help === c.SUPPRESS) { | ||
parts.push(null); | ||
@@ -567,3 +568,3 @@ if (inserts[actionIndex] === '|') { | ||
text = _.trim(text); | ||
text = text.trim(); | ||
@@ -577,4 +578,4 @@ // return the text | ||
var textWidth = this._width - this._currentIndent; | ||
var indentIncriment = _.repeat(' ', this._currentIndent); | ||
return this._fillText(text, textWidth, indentIncriment) + $$.EOL + $$.EOL; | ||
var indentIncriment = $$.repeat(' ', this._currentIndent); | ||
return this._fillText(text, textWidth, indentIncriment) + c.EOL + c.EOL; | ||
}; | ||
@@ -598,10 +599,10 @@ | ||
if (!action.help) { | ||
actionHeader = _.repeat(' ', this._currentIndent) + actionHeader + $$.EOL; | ||
actionHeader = $$.repeat(' ', this._currentIndent) + actionHeader + c.EOL; | ||
// short action name; start on the same line and pad two spaces | ||
} else if (actionHeader.length <= actionWidth) { | ||
actionHeader = _.repeat(' ', this._currentIndent) + | ||
actionHeader = $$.repeat(' ', this._currentIndent) + | ||
actionHeader + | ||
' ' + | ||
_.repeat(' ', actionWidth - actionHeader.length); | ||
$$.repeat(' ', actionWidth - actionHeader.length); | ||
indentFirst = 0; | ||
@@ -611,3 +612,3 @@ | ||
} else { | ||
actionHeader = _.repeat(' ', this._currentIndent) + actionHeader + $$.EOL; | ||
actionHeader = $$.repeat(' ', this._currentIndent) + actionHeader + c.EOL; | ||
indentFirst = helpPosition; | ||
@@ -623,10 +624,10 @@ } | ||
helpLines = this._splitLines(helpText, helpWidth); | ||
parts.push(_.repeat(' ', indentFirst) + helpLines[0] + $$.EOL); | ||
parts.push($$.repeat(' ', indentFirst) + helpLines[0] + c.EOL); | ||
helpLines.slice(1).forEach(function (line) { | ||
parts.push(_.repeat(' ', helpPosition) + line + $$.EOL); | ||
parts.push($$.repeat(' ', helpPosition) + line + c.EOL); | ||
}); | ||
// or add a newline if the description doesn't end with one | ||
} else if (actionHeader.charAt(actionHeader.length - 1) !== $$.EOL) { | ||
parts.push($$.EOL); | ||
} else if (actionHeader.charAt(actionHeader.length - 1) !== c.EOL) { | ||
parts.push(c.EOL); | ||
} | ||
@@ -679,5 +680,5 @@ // if there are any sub-actions, add their help as well | ||
if (_.isString(choices)) { | ||
if (typeof choices === 'string') { | ||
choices = choices.split('').join(', '); | ||
} else if (_.isArray(choices)) { | ||
} else if (Array.isArray(choices)) { | ||
choices = choices.join(','); | ||
@@ -687,3 +688,3 @@ } | ||
{ | ||
choices = _.keys(choices).join(','); | ||
choices = Object.keys(choices).join(','); | ||
} | ||
@@ -720,18 +721,18 @@ result = '{' + choices + '}'; | ||
break; | ||
case $$.OPTIONAL: | ||
case c.OPTIONAL: | ||
metavars = buildMetavar(1); | ||
result = '[' + metavars[0] + ']'; | ||
break; | ||
case $$.ZERO_OR_MORE: | ||
case c.ZERO_OR_MORE: | ||
metavars = buildMetavar(2); | ||
result = '[' + metavars[0] + ' [' + metavars[1] + ' ...]]'; | ||
break; | ||
case $$.ONE_OR_MORE: | ||
case c.ONE_OR_MORE: | ||
metavars = buildMetavar(2); | ||
result = '' + metavars[0] + ' [' + metavars[1] + ' ...]'; | ||
break; | ||
case $$.REMAINDER: | ||
case c.REMAINDER: | ||
result = '...'; | ||
break; | ||
case $$.PARSER: | ||
case c.PARSER: | ||
metavars = buildMetavar(1); | ||
@@ -753,3 +754,3 @@ result = metavars[0] + ' ...'; | ||
if (actionValue !== $$.SUPPRESS) { | ||
if (actionValue !== c.SUPPRESS) { | ||
params[actionProperty] = actionValue; | ||
@@ -760,10 +761,10 @@ } | ||
if (!!params.choices) { | ||
if (_.isString(params.choices)) { | ||
if (typeof params.choices === 'string') { | ||
params.choices = params.choices.split('').join(', '); | ||
} | ||
else if (_.isArray(params.choices)) { | ||
else if (Array.isArray(params.choices)) { | ||
params.choices = params.choices.join(', '); | ||
} | ||
else { | ||
params.choices = _.keys(params.choices).join(', '); | ||
params.choices = Object.keys(params.choices).join(', '); | ||
} | ||
@@ -782,3 +783,3 @@ } | ||
text = _.trim(text); | ||
text = text.trim(); | ||
text = text.replace(this._whitespaceMatcher, ' '); | ||
@@ -788,3 +789,3 @@ | ||
// is at most width characters long. | ||
text.split($$.EOL).forEach(function (line) { | ||
text.split(c.EOL).forEach(function (line) { | ||
if (width >= line.length) { | ||
@@ -820,3 +821,3 @@ lines.push(line); | ||
}); | ||
return lines.join($$.EOL); | ||
return lines.join(c.EOL); | ||
}; | ||
@@ -823,0 +824,0 @@ |
@@ -13,3 +13,3 @@ /** | ||
var _ = require('lodash'); | ||
var $$ = require('./utils'); | ||
@@ -22,3 +22,3 @@ /** | ||
var Namespace = module.exports = function Namespace(options) { | ||
_.extend(this, options); | ||
$$.extend(this, options); | ||
}; | ||
@@ -33,3 +33,3 @@ | ||
Namespace.prototype.isset = function (key) { | ||
return _.has(this, key); | ||
return $$.has(this, key); | ||
}; | ||
@@ -47,3 +47,3 @@ | ||
if (typeof (key) === 'object') { | ||
_.extend(this, key); | ||
$$.extend(this, key); | ||
} else { | ||
@@ -50,0 +50,0 @@ this[key] = value; |
{ | ||
"name": "argparse", | ||
"description": "Very powerful CLI arguments parser. Native port of argparse - python's options parsing library", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"keywords": [ | ||
@@ -17,2 +17,6 @@ "cli", | ||
], | ||
"files": [ | ||
"index.js", | ||
"lib/" | ||
], | ||
"license": "MIT", | ||
@@ -24,3 +28,2 @@ "repository": "nodeca/argparse", | ||
"dependencies": { | ||
"lodash": ">= 4.0.0 < 5.0.0", | ||
"sprintf-js": "~1.0.2" | ||
@@ -27,0 +30,0 @@ }, |
1
114990
27
3057
- Removedlodash@>= 4.0.0 < 5.0.0
- Removedlodash@4.17.21(transitive)