optparse-applicative

(typed) list of argument from a program using optparse-appplicative

旧街凉风 提交于 2019-12-25 02:16:27
问题 Is there a way to extract a list of names and types from a command line program, made using optparse-applicative ? I am +/- looking for some function of type ParserInfo a -> [(String,TypeRep)] 回答1: No, there is no way. The relevant bits are: data ParserInfo a = ParserInfo { infoParser :: Parser a , -- ... } 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 and do

Is it possible to have a optparse-applicative option with several parameters?

最后都变了- 提交于 2019-12-12 11:36:50
问题 I just found out that my carefully crafted parser fails to parse any string I throw at it: roi :: Parser (Maybe ROI) roi = optional $ option (ROI <$> auto <*> auto <*> auto <*> auto) $ long "roi" <> metavar "ROI" <> help "Only process selected region of interest" where ROI = ROI Int Int Int Int If that is important, it is nested in a higher parser options :: Parser Opts options = Opts <$> input <*> output <*> roi <*> startT <*> endT where Opts is an appropriate ADT. Now I assumed that the roi

How to parse an optional flag as a Maybe value?

自作多情 提交于 2019-12-12 07:32:05
问题 I'm trying to use optparse-applicative to parse a Maybe String but I can't find anywhere how to deal with Maybe . The only thing I found is to add a default value but I really need a Nothing if user didn't supply an option instead of "" . Is there any way to achieve this ? Here is an example of working code: import Options.Applicative data Config = Config { cIn :: String , cOut :: String } deriving Show configParser :: Parser Config configParser = Config <$> strOption (long "in" <> short 'i')

How to parse an optional flag as a Maybe value?

ε祈祈猫儿з 提交于 2019-12-03 05:36:01
I'm trying to use optparse-applicative to parse a Maybe String but I can't find anywhere how to deal with Maybe . The only thing I found is to add a default value but I really need a Nothing if user didn't supply an option instead of "" . Is there any way to achieve this ? Here is an example of working code: import Options.Applicative data Config = Config { cIn :: String , cOut :: String } deriving Show configParser :: Parser Config configParser = Config <$> strOption (long "in" <> short 'i') <*> strOption (long "out" <> short 'o') main :: IO () main = do conf <- execParser (info configParser

optparse-applicative Backtracking

假如想象 提交于 2019-12-01 23:28:02
问题 I'm trying to use the optparse-applicative library in an program which should perform a different action depending on the number of arguments. For example, the argument parsing for a program which calculates perimeters: module TestOpts where import Options.Applicative type Length = Double data PerimeterCommand = GeneralQuadranglePerimeter Length Length Length Length | RectanglePerimeter Length Length parsePerimeterCommand :: Parser PerimeterCommand parsePerimeterCommand = parseQuadPerimeter <

optparse-applicative Backtracking

ⅰ亾dé卋堺 提交于 2019-12-01 20:26:44
I'm trying to use the optparse-applicative library in an program which should perform a different action depending on the number of arguments. For example, the argument parsing for a program which calculates perimeters: module TestOpts where import Options.Applicative type Length = Double data PerimeterCommand = GeneralQuadranglePerimeter Length Length Length Length | RectanglePerimeter Length Length parsePerimeterCommand :: Parser PerimeterCommand parsePerimeterCommand = parseQuadPerimeter <|> parseRectPerimeter parseQuadPerimeter = GeneralQuadranglePerimeter <$> parseLength "SIDE1" <*>