Reputation: 6793
Given a Parser a
and a value of type a
is it possible to generate the relevant command-line (in textual format)? (Basically, the exact reverse of what optparse-applicative
is generally used for!)
For example, given something like...
data Args = {userName :: Text, userGroups :: Text }
parser :: Parser Args
parser = Args
<$> (strOption $ long "name")
<*> (many $ strOption $ long "group")
...how does one convert the following...
let args = Args { userName :: "testUser", userGroups :: ["system", "sudo"] }
...to...
--name=testUser --group=system --group=sudo
Upvotes: 1
Views: 118
Reputation: 153132
No, there is no way in general. The relevant bits are:
data Parser a
= forall x . MultP (Parser (x -> a)) (Parser x)
| forall x . BindP (Parser x) (x -> Parser a)
| -- ...
Since the x
s of MultP
and BindP
are existentially quantified, the information about the suitable x
s that could be used to produce your a
is lost at runtime.
Upvotes: 1