Skip to content
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

Overlapping flags and options or options with optional arguments #235

Closed
ollef opened this issue Oct 29, 2016 · 3 comments
Closed

Overlapping flags and options or options with optional arguments #235

ollef opened this issue Oct 29, 2016 · 3 comments

Comments

@ollef
Copy link

ollef commented Oct 29, 2016

Hey, and thanks for an excellent library!

Is there any way to get a -v flag working on its own but also allow passing it an argument, such as -vn?

Many command-line utilities support this idiom (e.g. ghc), but I haven't been able to get it to work with optparse-applicative. I tried the following (and a few different variations):

option auto
    (long "verbose"
    <> short 'v'
    <> metavar "LEVEL"
    <> help "Set the verbosity level to LEVEL")
<|>
flag 0 1
    (long "verbose"
    <> short 'v'
    <> help "Enable verbose mode")

but it seems like the option takes precedence.

Cheers!

@HuwCampbell
Copy link
Collaborator

Cheers.
No, there isn't a way to do this by design, as this situation can lead to an ambiguous parse. Please see #194 for more of an explanation.

@ollef
Copy link
Author

ollef commented Oct 30, 2016

Alright, I guess I'll have to live with the argument form then.

Feel free to close the issue if it won't happen. Thanks for your reply!

Perhaps this should be documented?

@HuwCampbell
Copy link
Collaborator

I'm adding this to the README

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants