some error-checking for option definitions

short options must be short, and you can't use names that mean something
already
This commit is contained in:
David Glasser
2014-02-04 18:06:22 -08:00
parent 7bf9d0a0d3
commit 42b5b76000

View File

@@ -47,11 +47,15 @@ var Command = function (options) {
_.extend(this, options);
_.each(this.options, function (value, key) {
if (key === "args" || key === "appDir")
throw new Error(options.name + ": bad option name " + key);
if (! _.has(value, 'type'))
value.type = String;
if (_.has(value, 'default') && _.has(value, 'required'))
throw new Error(options.name + ": " + key + " can't be both optional " +
"and required");
if (_.has(value, 'short') && value.short.length !== 1)
throw new Error(options.name + ": " + key + " has a bad short option");
});
};