1

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
Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60

1 Answers1

1

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 xs of MultP and BindP are existentially quantified, the information about the suitable xs that could be used to produce your a is lost at runtime.

Daniel Wagner
  • 145,880
  • 9
  • 220
  • 380