From bb43c2c750be20151ca76712ea5d2dd70c40291c Mon Sep 17 00:00:00 2001 From: Judah Jacobson Date: Mon, 15 Nov 2010 03:13:42 +0000 Subject: [PATCH] Finish the "add" command after an end-of-file. --- hledger/Hledger/Cli/Add.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hledger/Hledger/Cli/Add.hs b/hledger/Hledger/Cli/Add.hs index 4ed4b1882..cdb2d0930 100644 --- a/hledger/Hledger/Cli/Add.hs +++ b/hledger/Hledger/Cli/Add.hs @@ -28,6 +28,7 @@ import Control.Monad.Trans (liftIO) import System.Console.Haskeline.Completion import qualified Data.Set as Set import Safe (headMay) +import Control.Exception (throw) -- | Read transactions from the terminal, prompting for each field, @@ -151,7 +152,7 @@ getPostings ctx accept historicalps enteredps = do -- input is valid. May also raise an EOF exception if control-d is pressed. askFor :: String -> Maybe String -> Maybe (String -> Bool) -> InputT IO String askFor prompt def validator = do - l <- fmap (maybe "" id) + l <- fmap (maybe eofErr id) $ getInputLine $ prompt ++ maybe "" showdef def ++ ": " let input = if null l then fromMaybe l def else l case validator of @@ -159,7 +160,9 @@ askFor prompt def validator = do then return input else askFor prompt def validator Nothing -> return input - where showdef s = " [" ++ s ++ "]" + where + showdef s = " [" ++ s ++ "]" + eofErr = throw $ mkIOError eofErrorType "end of input" Nothing Nothing -- | Append this transaction to the journal's file, and to the journal's -- transaction list.