From 78542ca32e02062e2b1235545dde018c8704f542 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sun, 29 Nov 2020 15:28:14 -0800 Subject: [PATCH] check-dates: rename --strict to --unique; improve output --- hledger/Hledger/Cli/Commands/Checkdates.hs | 30 ++++++++++------------ 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/hledger/Hledger/Cli/Commands/Checkdates.hs b/hledger/Hledger/Cli/Commands/Checkdates.hs index 7b7bec50e..49b950e46 100755 --- a/hledger/Hledger/Cli/Commands/Checkdates.hs +++ b/hledger/Hledger/Cli/Commands/Checkdates.hs @@ -15,7 +15,7 @@ import Text.Printf checkdatesmode :: Mode RawOpts checkdatesmode = hledgerCommandMode $(embedFileRelative "Hledger/Cli/Commands/Checkdates.txt") - [flagNone ["strict"] (setboolopt "strict") "makes date comparing strict"] + [flagNone ["unique"] (setboolopt "unique") "require that dates are unique"] [generalflagsgroup1] hiddenflags ([], Just $ argsFlag "[QUERY]") @@ -25,26 +25,24 @@ checkdates CliOpts{rawopts_=rawopts,reportspec_=rspec} j = do let ropts = (rsOpts rspec){accountlistmode_=ALFlat} let ts = filter (rsQuery rspec `matchesTransaction`) $ jtxns $ journalSelectingAmountFromOpts ropts j - let strict = boolopt "strict" rawopts + let unique = boolopt "unique" rawopts let date = transactionDateFn ropts let compare a b = - if strict + if unique then date a < date b else date a <= date b case checkTransactions compare ts of - FoldAcc{fa_previous=Nothing} -> return () - FoldAcc{fa_error=Nothing} -> return () - FoldAcc{fa_error=Just error, fa_previous=Just previous} -> - (putStrLn $ printf ("ERROR: transaction out of%s date order" - ++ "\nPrevious date: %s" - ++ "\nDate: %s" - ++ "\nLocation: %s" - ++ "\nTransaction:\n\n%s") - (if strict then " STRICT" else "") - (show $ date previous) - (show $ date error) - (show $ tsourcepos error) - (showTransaction error)) >> exitFailure + FoldAcc{fa_previous=Nothing} -> return () + FoldAcc{fa_error=Nothing} -> return () + FoldAcc{fa_error=Just error, fa_previous=Just previous} -> do + putStrLn $ printf + ("Error: transaction's date is not in date order%s,\n" + ++ "at %s:\n\n%sPrevious transaction's date was: %s") + (if unique then " and/or not unique" else "") + (showGenericSourcePos $ tsourcepos error) + (showTransaction error) + (show $ date previous) + exitFailure data FoldAcc a b = FoldAcc { fa_error :: Maybe a