lukeed / sade

Smooth (CLI) Operator 🎶

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Disallow unknown options

sidvishnoi opened this issue · comments

It would be nice if there's a way to disallow unknown options. For example, mycommand --silent should throw an error with:

sade("mycommand", true).option("-v, --verbose", "desc", false);

A hack/workaround I wrote is:

  for (const key of Object.keys(opts)) {
    if (!cli.tree.__all__.alias.hasOwnProperty(key) && key !== "_") {
      const unknownOpt = key.length === 1 ? `-${key}` : `--${key}`;
      throw new Error(`Unknown option: ${unknownOpt}`);
    }
  }

Hey, it already does :) It's a parse option:

https://github.com/lukeed/sade#optsunknown

Oh! Awesome!