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

Poor error messages, poor extensibility

Open rkeene opened this issue 3 years ago • 0 comments

Currently this library does not have good error messages by default. For example, the example program:

const getopt = require('node-getopt');
const info = getopt.create([
	['t', 'test=ARG', 'Test']
]).bindHelp().parseSystem();

This has a few problems that result in poor error messages:

  • Using it as ./example.js --test results in: option test need argument ; The argument I used is "--test" not "test", this is what should be reported to the user. This is what GNU "ls" returns: ls: option '--format' requires an argument
  • Using it as ./example -t results in: option test need argument ; The argument I used is "-t" not "test" (or even "--test"), this is what should be reported to the user. This is what GNU "ls" returns: ls: option requires an argument -- 'I'

Further, there is no capability to fix this without modifying the library because the error() method is passed in an Error object with a string as its error, which does not contain enough information to determine what the error should actually be. This is poor extensibility.

rkeene avatar Apr 10 '21 12:04 rkeene