pkgjs / parseargs

Polyfill of `util.parseArgs()`
Apache License 2.0
121 stars 9 forks source link

Behavior of short with value including equals #126

Open bcoe opened 2 years ago

bcoe commented 2 years ago

I found the behavior of -a=5 surprising (I was assuming it would simply be the value "5").

test('when combine string short with value including equals then parsed with equals in value', (t) => {
  const args = ['-a=5'];
  const options = { alpha: { short: 'a', type: 'string' } };
  const expected = { values: { __proto__: null, alpha: '=5' }, positionals: [] };

  const result = parseArgs({ args, options });

  t.deepEqual(result, expected);
  t.end();
});

Can someone refresh me on how we landed on this behavior?

bakkot commented 2 years ago

See https://github.com/pkgjs/parseargs/issues/78. Most programs don't support = here; try, for example, grep -C=3 'foo'.

(That said, it might make sense for this to be an error, at least in strict: true, with a suggestion to do -C =3 if that's what you actually meant.)

shadowspawn commented 2 years ago

(Or support both, per #78. Thanks for supplying the previous issue @bakkot.)