我有一个现有的程序,它采用命令行参数(用户名,密码,日期),然后使用Network.HTTP.Conduit
库将xml消息发布到服务器。然后我解析结果,做一些工作并使用blaze-html写出文件。
这一切都像一个魅力; 但是,我想我会使用haskeline
这样密码就不可见了。我能够创建一个命令行程序来获取用户提供的值并将其打印出来,但是如果我调用使用 conduit 的函数,它永远不会返回。
这是有问题的代码:
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实际上正在运行。关于如何使这项工作的任何提示?
提前感谢,尼尔
您声称它适用于硬编码的用户名,密码,haskeline之前的日期。 为了帮助调试,也许您无法将管道提升到 InputT 中。 以下仍然失败吗? (我没有编译这个,所以请随时修复语法错误...
-- Isolate the haskeline monad to just the input part:
main = loop
where
loop :: IO ()
loop = do
(username,password,date) <- runInputT defaultSettings $ do
Just username <- getInputLine "WM username: "
Just password <- getPassword (Just '*') "WM password: "
Just date <- getInputLine "Date (YYYYMMDD): "
return (username,password,date)
putStrLn "querying WM..."
clients <- getWMClients username password
putStrLn "successfully retrieved client list from WM..."
let outHeader = renderHeader date username
putString <- mapM (x -> createString x clients) cList
writeFile (date ++ "_report.html") (outHeader ++ concat reportString)
putStrLn "Done"