Skip to content

apparently no way to implement --foo[=val] #243

@joeyh

Description

@joeyh

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions