-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
combining parsers with overlapping flags #85
Comments
I'm not sure what feature you are requesting here. Can you elaborate? See also #77. |
I want something(s) better than the import Options.Applicative; import Options.Applicative.Internal; import Options.Applicative.Types
import Data.Monoid
mapOptName :: (OptName -> OptName) -> Parser a -> Parser a
addPrefix :: String -> OptName -> OptName
-- both are defined above
step1 = (,) <$> switch (long "step1specific") <*> switch (short 'x')
step2 = (,) <$> switch (long "step2specific") <*> switch (short 'x')
steps = (,) <$> mapOptName (addPrefix "step1") step1
<*> mapOptName (addPrefix "step2") step2
run str = execParserPure (prefs mempty) (info steps mempty) str
{- ^
>>> run ["--step1-step1specific","--step2-step2specific","--step1-x","--step2-x"]
Success ((True,True),(True,True))
The above code works. I would like if it were possible to
make the following examples work without needing to make
substantial changes to the parsers.
>>> run ["--step1specific","--step2specific","--step2-x"]
Success ((True,False),(True,True))
>>> run ["-x"]
Success ((False,True),(False,True))
>>> run ["+step1","-x","-step1","--step2specific"]
Success ((False,True),(True,False))
-} |
I see. This is a sensible request, as the current semantics of sequencing of parsers with overlapping option names is a bit unsatisfactory (the second option cannot be parsed until the first one is). I think the proper way to handle this is to add a I'm not sure I'll be able to implement this right away, but patches are (as always) welcome :) |
Hi, I am also worried about current behavior. |
So I'm going to guess you're in subparser inline mode. If you move the flag to after the definitions of the commands it should work for you, as the inlined parser will be searched first. |
Could optparse-applicative provide more help when combining parsers that have the same flag names. For example:
Lets me write something like:
steps
accepts arguments like--step1-x --step2-x
ifstep
accepts-x
. Ideally the prefix could be left out when there is no conflict, but I thinkBindP
gets in the way of defining arenameOptNames :: ([OptName] -> [OptName]) -> Parser a -> Parser a
that sees allOptName
at once.uu-options supports
+blah -blah
delimiters. See section 5.2 of their techreportThe text was updated successfully, but these errors were encountered: