我有一个现有的程序,它接受命令行参数(用户名、密码、日期),然后使用该Network.HTTP.Conduit
库将 xml 消息发布到服务器。然后我解析结果,做一些工作并使用 blaze-html 写入文件。
这一切都像魅力一样。但是,我想我会使用haskeline
这样密码不可见。我可以创建一个命令行程序来获取用户提供的值并将它们打印出来,但是如果我调用使用管道的函数,它永远不会返回。
这是有问题的代码:
main = runInputT defaultSettings loop
where
loop :: InputT IO ()
loop = do
Just username <- getInputLine "WM username: "
Just password <- getPassword (Just '*') "WM password: "
Just date <- getInputLine "Date (YYYYMMDD): "
outputStrLn "querying WM..."
clients <- lift $ getWMClients username password
outputStrLn "successfully retrieved client list from WM..."
let outHeader = renderHeader date username
reportString <- mapM (\x -> createString x clients) cList
lift $ writeFile (date ++ "_report.html") (outHeader ++ concat reportString)
outputStrLn "Done"
函数 getWMClients 函数是:
getWMClients :: Username -> String -> IO [Client]
getWMClients username password = do
let f = [Size "-1", Skip "0"]
let fs = [Select "id",
Select "status",
Select "last-name",
Select "first-name",
]
let query = WMQuery {transaction=SHARE,service=Query,businessObject=CONT,field=f,fields=fs}
results <- doQuery username (Just password) Nothing (Just query)
rows <- xmlResultsToMaps results
let clients = map makeClient rows
return clients
当我运行程序时,它会挂在“查询 WM ...”处,我认为 http-conduit 从未真正运行过。关于如何使这项工作的任何提示?
提前致谢, 尼尔