corny
corny

Reputation: 7852

Haskell, documentation for unlabeled command line arguments in optparse-generic

I'm using optparse-generic to parse the command line arguments of a program called example. I have a datatype with an unnamed field. For example:

data Unlabeled = Unlabeled String deriving (Generic, Show)

This generates a program which can be called as follows: ./exmaple "foo". However, for the user, there is no documentation what the String-parameter is about. In particular, ./example --help does not give any valuable information about this positional String argument ./example expects.

Using named datatypes (record syntax), it is possible to add documentation to the datatype. For example

data Labeled = Labeled {name :: String <?> "Select the foo"} deriving (Generic, Show)

This generates help text for the program. For example, when called ./example --help, it will display --name STRING Select the foo.

How can I add documentation to unnamed datatypes in the same way as I can do for record-syntax-datatypes?

Upvotes: 1

Views: 82

Answers (1)

user2407038
user2407038

Reputation: 14598

data Labeled = Labeled (String <?> "Select the foo") will give you

...
STRING     Select the foo
... 

in the --help message. To perhaps clarify, the <?> is simply a type constructor, it is just syntactically an operator. Maybe fun fact: you can write data X = X (Int `Either` Bool) as well.

Upvotes: 1

Related Questions