You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The idea is that we keep a limited set of assumptions about names & values (ie. - is the prefix for shorthands & -- is the prefix for a flag... that's about it... no other validation). Notably, and something we should probably document, is that you can't ever make an alias/shorthand of "-" (as -- is a known/special identifier). Based on the current design though, we would interpret --- as if "-" is a flag name (ex. { args: { "-": true } ... } ~ which might be odd but is at least codified).
Throwing an error or even warning when we see --- would mean we're assuming the input is incorrect. I think, as a rule, we should always successfully parse all input without warning/error. Special cases/exception handling can be left to tooling authors that want to build off of this more primitive implementation.
Ex. of a simple two-liner someone could use to handle/warn of cases where --- is found...
// cli.js ---fooconst{ parseArgs }=require('util')const{ args }=parseArgs()// check for dashes & warnconsterrs=Object.keys(args).filter(name=>name.startsWith('-'))if(errs.length)console.error(`Arguments passed beginning with dashes`)// ! Arguments passed beginning with dashes
Activity
ljharb commentedon Apr 30, 2021
I would expect
---footo be the flag "-foo", or an error - ie, the third dash shouldn't change how things are parsed.joesepi commentedon May 14, 2021
If we want to avoid throwing errors, should we simply warn or info on such a case where more than 2 dashes are used?
ljharb commentedon May 14, 2021
Do we want that?
darcyclarke commentedon Oct 27, 2021
@joesepi I don't think we want that & this question seems to have now been asked/answered in the FAQs section (ref. https://github.com/pkgjs/parseargs#faqs), re.
The idea is that we keep a limited set of assumptions about names & values (ie.
-is the prefix for shorthands &--is the prefix for a flag... that's about it... no other validation). Notably, and something we should probably document, is that you can't ever make an alias/shorthand of"-"(as--is a known/special identifier). Based on the current design though, we would interpret---as if"-"is a flag name (ex.{ args: { "-": true } ... }~ which might be odd but is at least codified).Throwing an error or even warning when we see
---would mean we're assuming the input is incorrect. I think, as a rule, we should always successfully parse all input without warning/error. Special cases/exception handling can be left to tooling authors that want to build off of this more primitive implementation.Ex. of a simple two-liner someone could use to handle/warn of cases where
---is found...Do not strip excess leading dashes on long option names
shadowspawn commentedon Dec 22, 2021
Closed by #21