web: make --auto and multiple -f options work again
I think we lost one or both of these at the time of ecf49b1e.
			
			
This commit is contained in:
		
							parent
							
								
									9c1db9ed9f
								
							
						
					
					
						commit
						6a96683691
					
				| @ -20,7 +20,6 @@ import Network.Wai.Handler.Warp (runSettings, defaultSettings, setHost, setPort) | |||||||
| import Network.Wai.Handler.Launch (runHostPortUrl) | import Network.Wai.Handler.Launch (runHostPortUrl) | ||||||
| -- | -- | ||||||
| import Control.Monad | import Control.Monad | ||||||
| import Data.Default |  | ||||||
| import Data.Text (pack) | import Data.Text (pack) | ||||||
| import System.Exit (exitSuccess) | import System.Exit (exitSuccess) | ||||||
| import System.IO (hFlush, stdout) | import System.IO (hFlush, stdout) | ||||||
| @ -46,23 +45,25 @@ runWith opts | |||||||
|   | "binary-filename" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStrLn (binaryfilename progname) |   | "binary-filename" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStrLn (binaryfilename progname) | ||||||
|   | otherwise = do |   | otherwise = do | ||||||
|     requireJournalFileExists =<< (head `fmap` journalFilePathFromOpts (cliopts_ opts)) -- XXX head should be safe for now |     requireJournalFileExists =<< (head `fmap` journalFilePathFromOpts (cliopts_ opts)) -- XXX head should be safe for now | ||||||
|     withJournalDo' opts web |     withJournalDoWeb opts web | ||||||
| 
 | 
 | ||||||
| withJournalDo' :: WebOpts -> (WebOpts -> Journal -> IO ()) -> IO () | -- | A version of withJournalDo specialised for hledger-web. | ||||||
| withJournalDo' opts@WebOpts {cliopts_ = cliopts} cmd = do | -- Disallows the special - file to avoid some bug, | ||||||
|   f <- head `fmap` journalFilePathFromOpts cliopts -- XXX head should be safe for now | -- takes WebOpts rather than CliOpts. | ||||||
|  | withJournalDoWeb :: WebOpts -> (WebOpts -> Journal -> IO ()) -> IO () | ||||||
|  | withJournalDoWeb opts@WebOpts {cliopts_ = copts} cmd = do | ||||||
|  |   journalpaths <- journalFilePathFromOpts copts | ||||||
| 
 | 
 | ||||||
|   -- https://github.com/simonmichael/hledger/issues/202 |   -- https://github.com/simonmichael/hledger/issues/202 | ||||||
|   -- -f- gives [Error#yesod-core] <stdin>: hGetContents: illegal operation (handle is closed) for some reason |   -- -f- gives [Error#yesod-core] <stdin>: hGetContents: illegal operation (handle is closed) | ||||||
|   -- Also we may be writing to this file. Just disallow it. |   -- Also we may try to write to this file. Just disallow -. | ||||||
|   when (f == "-") $ error' "hledger-web doesn't support -f -, please specify a file path" |   when (head journalpaths == "-") $  -- always non-empty | ||||||
|  |     error' "hledger-web doesn't support -f -, please specify a file path" | ||||||
| 
 | 
 | ||||||
|   let fn = cmd opts |   -- keep synced with withJournalDo  TODO refactor | ||||||
|          . pivotByOpts cliopts |   readJournalFiles (inputopts_ copts) journalpaths  | ||||||
|          . anonymiseByOpts cliopts |   >>= mapM (journalTransform copts) | ||||||
|        <=< journalApplyValue (reportopts_ cliopts) |   >>= either error' (cmd opts) | ||||||
|        <=< journalAddForecast cliopts |  | ||||||
|   readJournalFile def f >>= either error' fn |  | ||||||
| 
 | 
 | ||||||
| -- | The web command. | -- | The web command. | ||||||
| web :: WebOpts -> Journal -> IO () | web :: WebOpts -> Journal -> IO () | ||||||
|  | |||||||
| @ -10,6 +10,7 @@ module Hledger.Cli.Utils | |||||||
|     ( |     ( | ||||||
|      withJournalDo, |      withJournalDo, | ||||||
|      writeOutput, |      writeOutput, | ||||||
|  |      journalTransform, | ||||||
|      journalApplyValue,  |      journalApplyValue,  | ||||||
|      journalAddForecast, |      journalAddForecast, | ||||||
|      generateAutomaticPostings, |      generateAutomaticPostings, | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user