node-argp icon indicating copy to clipboard operation
node-argp copied to clipboard

Pass option name as parameter to reviver function

Open chrisnovakovic opened this issue 8 years ago • 0 comments

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.

chrisnovakovic avatar Sep 10 '16 23:09 chrisnovakovic