Closed blakeembrey closed 5 years ago
This may actually be related to https://github.com/zeit/arg/issues/6, since stopping early would kind of solve that use-case (assuming it's entirely ordered)
I believe we did solve that with permissive: true
. However, @Qix- and I discussed this one for a while. If one wanted to truly stop parsing early, we need to ditch the ƒ(spec, args) -> Object
signature in favor of returning a generator that emits parsed tokens.
The conclusion at that point was that generators would indeed be the perfect base abstraction, and that one could then 'objectify' it, but that in general it would just add lots of complexity for a fairly niche use-case.
@rauchg Interesting that --permissive
solved the use-case, unfortunately it wouldn't solve mine since I need to stop immediately. I created a sample PR and it seems pretty simple to support so maybe we slightly different cases in mind. How do you separate possible conflicts between the root command and sub-commands with permissive (or is it just ignored)?
Another way to solve this could be to allow { _: Handler }
and support returning a symbol to break parsing, but I opted to keep it simple with just a stopEarly: true
option that stops once you add an argument to result._
.
See https://github.com/zeit/arg/issues/6#issuecomment-450000740 - does that sound about right?
@Qix- Not quite sure what you're referring to, but do you want me to call it stopAtPositional
instead of stopEarly
? I just used stopEarly
since it's what minimist
also used, but I'm not tied to either way. I do need this feature, however, for projects like ts-node
to work.
stopEarly
is fine I suppose but it doesn't really indicate what "early" means. If I see stopEarly
in someone's code without knowing what arg
is, I'll have to look up what it means. stopAtPositional
tells me everything I need to know about the behavior therein.
@Qix- Great, I'll update the PR 👍
Released as 4.1.0
.
In some projects, I need the ability to "stop early" when parsing the arguments. I want it to parse up until the first
_
argument and then break. This is useful for projects such as https://github.com/TypeStrong/ts-node (like node.js core), where the arguments before the script file are part of the execution and after the script name part of the script arguments.