Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added 'resolve' conflict handler that (as of now) adds your new argument

  • Loading branch information...
commit ef5c954a877e668c7b9a481b26fa3eaaea8c259e 1 parent f67f474
William Collins authored
Showing with 10 additions and 2 deletions.
  1. +8 −2 lib/action_container.js
  2. +2 −0  lib/argument_parser.js
View
10 lib/action_container.js
@@ -39,6 +39,7 @@ var argumentErrorHelper = require('./argument/error');
* - `description` -- A description of what the program does
* - `prefixChars` -- Characters that prefix optional arguments
* - `argumentDefault` -- The default value for all arguments
+ * - `conflictHandler` -- The conflict handler to use for duplicate arguments
**/
var ActionContainer = module.exports = function ActionContainer(options) {
options = options || {};
@@ -46,8 +47,7 @@ var ActionContainer = module.exports = function ActionContainer(options) {
this.description = options.description;
this.argumentDefault = options.argumentDefault;
this.prefixChars = options.prefixChars || '';
-
- // ToDo conflict handler
+ this.conflictHandler = options.conflictHandler;
// set up registries
this._registries = {};
@@ -416,6 +416,7 @@ ActionContainer.prototype._popActionClass = function (options, defaultValue) {
};
ActionContainer.prototype._checkConflict = function (action) {
+ var conflictHandler = this._container.conflictHandler;
var optionStringActions = this._optionStringActions;
var conflictOptionals = [];
@@ -427,6 +428,11 @@ ActionContainer.prototype._checkConflict = function (action) {
});
if (conflictOptionals.length > 0) {
+
+ if (conflictHandler === 'resolve') {
+ return;
+ }
+
throw argumentErrorHelper(
action,
_.str.sprintf('Conflicting option string(s): %(conflict)s', {
View
2  lib/argument_parser.js
@@ -41,6 +41,7 @@ var Namespace = require('./namespace');
* - `prefixChars` Characters that prefix optional arguments
* - `argumentDefault` The default value for all arguments
* - `addHelp` Add a -h/-help option
+ * - `conflictHandler` Specifies how to handle conflicting argument names
* - `debug` Enable debug mode. Argument errors throw exception in
* debug mode and process.exit in normal. Used for development and
* testing (default: false)
@@ -68,6 +69,7 @@ var ArgumentParser = module.exports = function ArgumentParser(options) {
this.version = options.version;
this.debug = (options.debug === true);
+ this.conflictHandler = options.conflictHandler;
this.formatterClass = (options.formatterClass || HelpFormatter);
Please sign in to comment.
Something went wrong with that request. Please try again.