本文介绍了如何用optparse-appative来解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正尝试使用来解析 a>:
See the following passage of the code> Combinator in Control.Applicative :
optional $ strOption ( long "output" <> metavar "DIRECTORY" )
因此,您只需将可选的组合子应用于 strOption $ c的结果$ c $:
$ b
Accordingly, all you have to do is apply the optional combinator to the result of strOption:
import Options.Applicative data Config = Config { cIn :: Maybe String , cOut :: Maybe String } deriving Show configParser :: Parser Config configParser = Config <$> (optional $ strOption $ long "in" <> short 'i') <*> (optional $ strOption $ long "out" <> short 'o') main :: IO () main = do conf <- execParser (info configParser fullDesc) print conf
命令行测试:
$ main --in foo -o bar Config {cIn = Just "foo", cOut = Just "bar"} $ main -i foo Config {cIn = Just "foo", cOut = Nothing}
这篇关于如何用optparse-appative来解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!