2021-01-12 21:55:00 +03:00
|
|
|
#!/usr/bin/env stack
|
2021-02-13 00:55:31 +03:00
|
|
|
-- stack runghc --verbosity info --package hledger --package string-qq
|
2021-01-12 22:07:29 +03:00
|
|
|
-- Run from inside the hledger source tree, or compile with compile.sh.
|
|
|
|
-- See hledger-check-fancyassertions.hs.
|
2019-07-16 07:19:52 +03:00
|
|
|
|
2022-08-23 13:58:31 +03:00
|
|
|
{-# OPTIONS_GHC -Wno-missing-signatures #-}
|
2019-07-17 01:31:18 +03:00
|
|
|
{-# LANGUAGE NamedFieldPuns #-}
|
|
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
{-# LANGUAGE RecordWildCards #-}
|
2019-07-16 07:19:52 +03:00
|
|
|
|
2020-08-15 19:06:09 +03:00
|
|
|
import Data.String.QQ (s)
|
2022-06-01 02:33:45 +03:00
|
|
|
import qualified Data.Text.IO as T
|
2019-07-16 07:19:52 +03:00
|
|
|
import Hledger
|
|
|
|
import Hledger.Cli
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
cmdmode = hledgerCommandMode
|
2020-08-15 19:06:09 +03:00
|
|
|
[s| swap-dates
|
2019-07-17 01:31:18 +03:00
|
|
|
Swap date and date2, on transactions which have date2 defined.
|
|
|
|
(Does not yet swap posting dates.)
|
2020-08-15 21:29:35 +03:00
|
|
|
_FLAGS
|
2019-07-16 07:19:52 +03:00
|
|
|
|]
|
|
|
|
[]
|
|
|
|
[generalflagsgroup1]
|
|
|
|
[]
|
|
|
|
([], Nothing) -- Just $ argsFlag "[QUERY]")
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = do
|
2020-12-30 09:59:12 +03:00
|
|
|
opts@CliOpts{reportspec_=rspec} <- getHledgerCliOpts cmdmode
|
2019-07-16 07:19:52 +03:00
|
|
|
withJournalDo opts $
|
2019-07-17 01:31:18 +03:00
|
|
|
\j -> do
|
2019-07-16 07:19:52 +03:00
|
|
|
d <- getCurrentDay
|
|
|
|
let
|
2021-09-08 10:27:49 +03:00
|
|
|
q = _rsQuery rspec
|
2021-05-13 14:00:25 +03:00
|
|
|
ts = filter (q `matchesTransaction`) $ jtxns $ journalApplyValuationFromOpts rspec j
|
2019-07-17 01:31:18 +03:00
|
|
|
ts' = map transactionSwapDates ts
|
2021-01-01 01:43:00 +03:00
|
|
|
mapM_ (T.putStrLn . showTransaction) ts'
|
2019-07-17 01:31:18 +03:00
|
|
|
|
|
|
|
transactionSwapDates :: Transaction -> Transaction
|
|
|
|
transactionSwapDates t@Transaction{tdate2=Nothing} = t
|
|
|
|
transactionSwapDates t@Transaction{tdate2=Just d} = t{tdate=d, tdate2=Just $ tdate t}
|