Skip to content

Pass option name as parameter to reviver function#6

Open
chrisnovakovic wants to merge 1 commit intogagle:masterfrom
chrisnovakovic:reviver-option
Open

Pass option name as parameter to reviver function#6
chrisnovakovic wants to merge 1 commit intogagle:masterfrom
chrisnovakovic:reviver-option

Conversation

@chrisnovakovic
Copy link
Copy Markdown

Here's a small change to the invocation of an option's reviver function that informs the function of the option name. This allows reviver functions to fail with error messages written in the same style as the default ones provided by argp, e.g.:

reviver: function(value, option) {
  if (value > 5) {
    this.fail("Option '" + option + "' is not under 5");
  } else {
    return value;
  }
}

Without this option parameter, the reviver function doesn't know whether the user supplied the short or long version of the option, and can't produce that style of error message.

The reviver function is now passed a second parameter to the reviver
function for an option, containing the name of the option for which the
reviver function is being called.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant