Documentation clearly mention the use 'def', which provides a default value (empty) for the flag
sample = Sample{hello = def &= help "World argument" &= opt "world"}
&= summary "Sample v1"
but I couldn't find a way to mention that I want to force the flag to be required.
Should I really go for Explicit or is there any way to define a required flag in Implicit?
The documentation for opt
states that
Note that all flags in CmdArgs are optional, and if omitted will use their default value.
So it seems that it's not possible to define a flag as mandatory using the implicit style.
You can, however, detect the omission of a flag by using a Maybe
value. E.g.
data Sample = Sample { hello :: Maybe String }
sample = Sample{hello = def &= help "World argument" &= opt "world"}
&= summary "Sample v1"
Now if the flag is omitted, you get a Nothing
and if the user provides a value, you get Just "value"
. This means that you can check for Nothing
yourself and terminate with an appropriate error message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With