我正在尝试使用 optparse-applicative 解析对列表。解析单个对有效,但使用many
组合器解析任意多个会失败。
import Options.Applicative
pairParser = (,) <$> argument str (metavar "s1")
<*> argument str (metavar "s2")
testParser p = getParseResult . execParserPure (prefs idm)
(info (helper <*> p) fullDesc)
main = do
print $ testParser pairParser ["one", "two"]
print $ testParser (many pairParser) []
print $ testParser (many pairParser) ["one", "two"]
print $ testParser (many pairParser) ["one", "two", "three", "four"]
输出:
Just ("one","two") <- good
Just [] <- still good
Nothing <- does not work
Nothing <- also does not work
有任何想法吗?