add: clearer prompts, more validation, use . to end as well
This commit is contained in:
parent
d4a3a8c3a0
commit
6ddf394119
@ -51,10 +51,10 @@ add :: CliOpts -> Journal -> IO ()
|
|||||||
add opts j
|
add opts j
|
||||||
| f == "-" = return ()
|
| f == "-" = return ()
|
||||||
| otherwise = do
|
| otherwise = do
|
||||||
|
hPrintf stderr "Adding transactions to journal file \"%s\".\n" f
|
||||||
hPutStrLn stderr $
|
hPutStrLn stderr $
|
||||||
"Enter one or more transactions, which will be added to your journal file.\n"
|
"To complete a transaction, enter . (period) at an account prompt.\n"
|
||||||
++"To complete a transaction, enter . when prompted for an account.\n"
|
++"To stop adding transactions, enter . at a date prompt, or control-d/control-c."
|
||||||
++"To quit, press control-d or control-c."
|
|
||||||
today <- getCurrentDay
|
today <- getCurrentDay
|
||||||
getAndAddTransactions j opts today
|
getAndAddTransactions j opts today
|
||||||
`catch` (\e -> unless (isEOFError e) $ ioError e)
|
`catch` (\e -> unless (isEOFError e) $ ioError e)
|
||||||
@ -75,10 +75,12 @@ getTransaction :: Journal -> CliOpts -> Day
|
|||||||
-> IO (Transaction,Day)
|
-> IO (Transaction,Day)
|
||||||
getTransaction j opts defaultDate = do
|
getTransaction j opts defaultDate = do
|
||||||
today <- getCurrentDay
|
today <- getCurrentDay
|
||||||
datestr <- runInteractionDefault $ askFor "date"
|
datestr <- runInteractionDefault $ askFor "date, or . to end"
|
||||||
(Just $ showDate defaultDate)
|
(Just $ showDate defaultDate)
|
||||||
(Just $ \s -> null s ||
|
(Just $ \s -> null s
|
||||||
isRight (parse (smartdate >> many spacenonewline >> eof) "" $ lowercase s))
|
|| s == "."
|
||||||
|
|| isRight (parse (smartdate >> many spacenonewline >> eof) "" $ lowercase s))
|
||||||
|
when (datestr == ".") $ ioError $ mkIOError eofErrorType "" Nothing Nothing
|
||||||
description <- runInteractionDefault $ askFor "description" (Just "") Nothing
|
description <- runInteractionDefault $ askFor "description" (Just "") Nothing
|
||||||
let historymatches = transactionsSimilarTo j (patterns_ $ reportopts_ opts) description
|
let historymatches = transactionsSimilarTo j (patterns_ $ reportopts_ opts) description
|
||||||
bestmatch | null historymatches = Nothing
|
bestmatch | null historymatches = Nothing
|
||||||
@ -117,9 +119,15 @@ getPostings st enteredps = do
|
|||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
where Just ps = historicalps
|
where Just ps = historicalps
|
||||||
defaultaccount = maybe Nothing (Just . showacctname) bestmatch
|
defaultaccount = maybe Nothing (Just . showacctname) bestmatch
|
||||||
account <- runInteraction j $ askFor (printf "account %d" n) defaultaccount (Just accept)
|
ordot | null enteredps || length enteredrealps == 1 = ""
|
||||||
|
| otherwise = ", or . to record"
|
||||||
|
account <- runInteraction j $ askFor (printf "account %d%s" n ordot) defaultaccount (Just accept)
|
||||||
if account=="."
|
if account=="."
|
||||||
then return enteredps
|
then
|
||||||
|
if null enteredps
|
||||||
|
then do hPutStrLn stderr $ "\nPlease enter some postings first."
|
||||||
|
getPostings st enteredps
|
||||||
|
else return enteredps
|
||||||
else do
|
else do
|
||||||
let defaultacctused = Just account == defaultaccount
|
let defaultacctused = Just account == defaultaccount
|
||||||
historicalps' = if defaultacctused then historicalps else Nothing
|
historicalps' = if defaultacctused then historicalps else Nothing
|
||||||
|
|||||||
@ -5,14 +5,14 @@
|
|||||||
rm -f t$$.j; bin/hledger -f t$$.j add; rm -f t$$.j
|
rm -f t$$.j; bin/hledger -f t$$.j add; rm -f t$$.j
|
||||||
<<<
|
<<<
|
||||||
2009/1/32
|
2009/1/32
|
||||||
>>> /date .*: date .*/
|
>>> /date, or \. to end.*: date, or \. to end.*/
|
||||||
>>>=0
|
>>>=0
|
||||||
|
|
||||||
# 2. should accept a blank date
|
# 2. should accept a blank date
|
||||||
rm -f t$$.j; bin/hledger -f t$$.j add; rm -f t$$.j
|
rm -f t$$.j; bin/hledger -f t$$.j add; rm -f t$$.j
|
||||||
<<<
|
<<<
|
||||||
|
|
||||||
>>> /date .*: description/
|
>>> /date,.*: description/
|
||||||
>>>=0
|
>>>=0
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
@ -28,7 +28,7 @@ a
|
|||||||
b
|
b
|
||||||
|
|
||||||
.
|
.
|
||||||
>>> /^date \[.*\]: description \[\]: account 1: amount 1: account 2: amount 2 \[-1000.0\]: account 3: date \[.*\]: $/
|
>>> /^date, or \. to end \[.*\]: description \[\]: account 1: amount 1: account 2: amount 2 \[-1000.0\]: account 3, or \. to record: date, or \. to end \[.*\]: $/
|
||||||
>>>=0
|
>>>=0
|
||||||
|
|
||||||
# 4. default commodity with greater precision
|
# 4. default commodity with greater precision
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user