fix reading from stdin, except for ui command

This commit is contained in:
Simon Michael 2009-01-17 19:23:21 +00:00
parent a51596899f
commit 59d110e0a8

View File

@ -76,8 +76,10 @@ main = do
parseLedgerAndDo :: [Opt] -> [String] -> ([Opt] -> [String] -> Ledger -> IO ()) -> IO () parseLedgerAndDo :: [Opt] -> [String] -> ([Opt] -> [String] -> Ledger -> IO ()) -> IO ()
parseLedgerAndDo opts args cmd = do parseLedgerAndDo opts args cmd = do
refdate <- today refdate <- today
-- ack, we're reading the file twice in order to save the text
f <- ledgerFilePathFromOpts opts f <- ledgerFilePathFromOpts opts
rawtext <- readFile f -- XXX we read the file twice - inelegant
-- and, doesn't work with stdin. kludge it, stdin won't work with ui command
let f' = if f == "-" then "/dev/null" else f
rawtext <- readFile f'
let runcmd = cmd opts args . prepareLedger opts args refdate rawtext let runcmd = cmd opts args . prepareLedger opts args refdate rawtext
return f >>= runErrorT . parseLedgerFile >>= either (hPutStrLn stderr) runcmd return f >>= runErrorT . parseLedgerFile >>= either (hPutStrLn stderr) runcmd