pcapriotti / pcapriotti/optparse-applicative
apparently no way to implement --foo[=val]
Nobody has claimed this yet.
- Dominant language
- Haskell
- Stars
- 959
- Forks
- 123
- Avg merge
- 3d 19h
- Merged PRs (30d)
- 1
Description
It's a fairly common pattern for an option --foo to set some default value, and --foo=val to set some more specific value. (With the equals sign being required before the value; a space is ambiguous in this case.)
I cannot find a way to implement this with optparse-applicative, without renaming one of the options from --foo to --bar.
This code compiles, and usage shows "[--foo ARG] | [--foo]", but parsing "--foo" fails.
data Foo = FooStr String | FooBool Bool
parser = (FooStr <$> strOption (long "foo")) <|> (FooBool <$> switch (long "foo"))
I don't really like that as a way of implementing it even if it worked, due to the redundancy.
Could there be a version of option that takes a default value, for when no value is provided?
(#242 touches on this, but is also about a regression)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the option and switch parser combinators described in the issue, including the strOption, switch, and option entry points. Determine how one --foo spelling could distinguish a bare flag from a required --foo=val, then verify that the parser accepts both forms without requiring duplicate option declarations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100