Skip to content

Commit

Permalink
Print CLI usage when unknown options are passed
Browse files Browse the repository at this point in the history
  • Loading branch information
astefanutti committed Jul 5, 2024
1 parent cad6569 commit 2c82300
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions libs/nomnom.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,18 +423,27 @@ class ArgParser {
}
return str;
}
opt(arg) {
opt(arg, value) {
// get the specified opt for this parsed arg
var match = Opt({});
var match;
this.specs.forEach(function (opt) {
if (opt.matches(arg)) {
match = opt;
}
});
if (!match) {
if (typeof value == "string") {
this.print("invalid argument '" + value + "'"
+ " \n\n" + this.getUsage(), 1);
} else {
this.print("invalid option '" + (arg.length == 1 ? "-" : "--") + arg + "'"
+ " \n\n" + this.getUsage(), 1);
}
}
return match;
}
setOption(options, arg, value) {
var option = this.opt(arg);
var option = this.opt(arg, value);
if (option.callback) {
var message = option.callback(value);

Expand Down

0 comments on commit 2c82300

Please sign in to comment.