Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

argparse

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

argparse - npm Package Compare versions

Comparing version 0.1.11 to 0.1.12

test/conflict.js

5

HISTORY.md

@@ -0,1 +1,6 @@

0.1.12 / 2013-02-10
* Fixed conflictHandler (#46), @hpaulj
0.1.11 / 2013-02-07

@@ -2,0 +7,0 @@

69

lib/action_container.js

@@ -68,2 +68,5 @@ /** internal

// raise an exception if the conflict handler is invalid
this._getHandler();
// action storage

@@ -282,3 +285,3 @@ this._actions = [];

if (actionIndex >= 0) {
this._actions.splice(actionIndex);
this._actions.splice(actionIndex, 1);
}

@@ -395,3 +398,3 @@ };

delete options.dest;
if (!dest) {

@@ -427,4 +430,15 @@ var optionStringDest = optionStringsLong.length ? optionStringsLong[0] :optionStrings[0];

ActionContainer.prototype._getHandler = function () {
var handlerString = this.conflictHandler;
var handlerFuncName = "_handleConflict" + _.str.capitalize(handlerString);
var func = this[handlerFuncName];
if (typeof func === 'undefined') {
var msg = "invalid conflict resolution value: " + handlerString;
throw new Error(msg);
} else {
return func;
}
};
ActionContainer.prototype._checkConflict = function (action) {
var conflictHandler = this._container.conflictHandler;
var optionStringActions = this._optionStringActions;

@@ -434,5 +448,7 @@ var conflictOptionals = [];

// find all options that conflict with this option
// collect pairs, the string, and an existing action that it conflicts with
action.optionStrings.forEach(function (optionString) {
if (!!optionStringActions[optionString]) {
conflictOptionals.push(optionString);
var conflOptional = optionStringActions[optionString];
if (typeof conflOptional !== 'undefined') {
conflictOptionals.push([optionString, conflOptional]);
}

@@ -442,15 +458,36 @@ });

if (conflictOptionals.length > 0) {
var conflictHandler = this._getHandler();
conflictHandler.call(this, action, conflictOptionals);
}
};
if (conflictHandler === 'resolve') {
this._removeAction(optionStringActions['--glop']);
return;
ActionContainer.prototype._handleConflictError = function (action, conflOptionals) {
var conflicts = _.map(conflOptionals, function (pair) {return pair[0]; });
conflicts = conflicts.join(', ');
throw argumentErrorHelper(
action,
_.str.sprintf('Conflicting option string(s): %(conflict)s', {
conflict: conflicts
})
);
};
ActionContainer.prototype._handleConflictResolve = function (action, conflOptionals) {
// remove all conflicting options
var self = this;
conflOptionals.forEach(function (pair) {
var optionString = pair[0];
var conflictingAction = pair[1];
// remove the conflicting option string
var i = conflictingAction.optionStrings.indexOf(optionString);
if (i >= 0) {
conflictingAction.optionStrings.splice(i, 1);
}
throw argumentErrorHelper(
action,
_.str.sprintf('Conflicting option string(s): %(conflict)s', {
conflict: conflictOptionals.join(', ')
})
);
}
delete self._optionStringActions[optionString];
// if the option now has no option string, remove it from the
// container holding it
if (conflictingAction.optionStrings.length === 0) {
conflictingAction.container._removeAction(conflictingAction);
}
});
};

@@ -57,12 +57,13 @@ /**

options = options || {};
options.description = (options.description || null);
options.argumentDefault = (options.argumentDefault || null);
options.prefixChars = (options.prefixChars || '-');
options.conflictHandler = (options.conflictHandler || 'error');
ActionContainer.call(this, options);
options.addHelp = (options.addHelp === undefined || !!options.addHelp);
options.parents = (options.parents || []);
options.argumentDefault = options.argumentDefault || null;
// default program name
options.prog = (options.prog || Path.basename(process.argv[1]));
ActionContainer.call(this, options);
this.prog = options.prog;

@@ -74,3 +75,2 @@ this.usage = options.usage;

this.debug = (options.debug === true);
this.conflictHandler = options.conflictHandler;

@@ -288,3 +288,3 @@ this.formatterClass = (options.formatterClass || HelpFormatter);

var res = this._parseKnownArgs(args, namespace);
namespace = res[0];

@@ -336,3 +336,3 @@ args = res[1];

});
// find all option indices, and determine the arg_string_pattern

@@ -462,3 +462,3 @@ // which has an 'O' if there is an option at an index,

else {
start = startIndex + 1;

@@ -472,3 +472,3 @@ var selectedPatterns = argStringsPattern.substr(start);

args = argStrings.slice(start, stop);
actionTuples.push([action, args, optionString]);

@@ -513,3 +513,3 @@ break;

});
// slice off the Positionals that we just parsed and return the

@@ -562,3 +562,3 @@ // index at which the Positionals' string args stopped

}
// if we consumed all the positionals we could and we're not

@@ -603,3 +603,3 @@ // at the index of an option string, there were extra arguments

});
// if no actions were used, report the error

@@ -699,3 +699,3 @@ if (!actionUsed) {

var i, j;
var getLength = function (string) {

@@ -920,3 +920,3 @@ return string.length;

if (argStrings.length === 0 && action.nargs === $$.OPTIONAL) {
value = (action.isOptional()) ? action.constant: action.defaultValue;

@@ -1023,3 +1023,3 @@

}
if (_.isString(choices)) {

@@ -1026,0 +1026,0 @@ choices = choices.split('').join(', ');

@@ -37,2 +37,3 @@ /** internal

// add any missing keyword arguments by checking the container
options.conflictHandler = (options.conflictHandler || container.conflictHandler);
options.prefixChars = (options.prefixChars || container.prefixChars);

@@ -70,4 +71,7 @@ options.argumentDefault = (options.argumentDefault || container.argumentDefault);

ActionContainer.prototype._removeAction.call(this, action);
this._groupActions.splice(action);
var actionIndex = this._groupActions.indexOf(action);
if (actionIndex >= 0) {
this._groupActions.splice(actionIndex, 1);
}
};
{
"name" : "argparse",
"description" : "Very powerful CLI arguments parser. Native port of argparse - python's options parsing library",
"version" : "0.1.11",
"version" : "0.1.12",
"keywords" : ["cli", "parser", "argparse", "option", "args"],

@@ -6,0 +6,0 @@ "homepage" : "https://github.com/nodeca/argparse",

@@ -118,13 +118,2 @@ /*global describe, it*/

it("should overwrite arguments when given the 'resolve' conflictHandler", function () {
parser = new ArgumentParser({conflictHandler: 'resolve'});
parser.addArgument(['--foo'], {help: 'old foo'});
parser.addArgument(['--foo'], {help: 'new foo'});
var help = parser._optionStringActions['--foo'].help;
assert.equal(help, 'new foo');
});
it("should parse negative arguments", function () {

@@ -131,0 +120,0 @@ parser = new ArgumentParser({debug: true});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc