sdiehl / repline

Haskeline wrapper for GHCi-like REPL interfaces
MIT License
107 stars 28 forks source link

autocomplete optparse-applicative parsers ? #32

Closed teto closed 4 years ago

teto commented 4 years ago

I would like to rewrite one of my program from python to haskell. My program relies on https://github.com/python-cmd2/cmd2 and makes extensive use of cmd2 autocompletion based on python's argparse parsers. I was wondering if there was a similar possibility (out of the box) with repline to accept an optparse-applicative parser and autocompletes that Parser ? If not do you know any similar library that would do it ?

sdiehl commented 4 years ago

This is a neat idea, probably a bit outside the scope of this package but one could certainly envision a repline-optparse that converted the optparse Parser type into a repline completion function. If you were to do this you would probably write a function which maps this datatype in optparse-applicacative into a completer:

data Parser a
  = NilP (Maybe a)
  | OptP (Option a)
  | forall x . MultP (Parser (x -> a)) (Parser x)
  | AltP (Parser a) (Parser a)
  | forall x . BindP (Parser x) (x -> Parser a)

Probably in a function with the following signature:

optparse :: MonadIO m => Parser a -> CompletionFunc m
teto commented 4 years ago

thanks, I will try to do that.