bin: add hledger-swap-dates

This commit is contained in:
Simon Michael 2019-07-16 05:19:52 +01:00
parent bc95f39757
commit 8bdcd9b38c
2 changed files with 43 additions and 0 deletions

View File

@ -10,6 +10,7 @@ They are:
- hledger-check.hs - check more complex account balance assertions
- hledger-smooth.hs - an attempt at automatically splitting infrequent/irregular transactions
- hledger-swap-dates.hs - swap all date and date2 fields
A reminder from http://hledger.org/hledger.html#add-on-commands :
when using the main hledger executable to run add-on commands, remember

42
bin/hledger-swap-dates.hs Executable file
View File

@ -0,0 +1,42 @@
#!/usr/bin/env stack
{- stack runghc --verbosity info
--package hledger-lib
--package hledger
--package here
--package text
-}
{-# LANGUAGE QuasiQuotes #-}
{-# OPTIONS_GHC -Wno-missing-signatures -Wno-name-shadowing #-}
import Data.List
import Data.String.Here
import qualified Data.Text.IO as T
import Hledger
import Hledger.Cli
------------------------------------------------------------------------------
cmdmode = hledgerCommandMode
[here| swap-dates
Swap date and date2, on transactions and postings which have date2 defined.
FLAGS
|]
[]
[generalflagsgroup1]
[]
([], Nothing) -- Just $ argsFlag "[QUERY]")
------------------------------------------------------------------------------
main :: IO ()
main = do
opts <- getHledgerCliOpts cmdmode
withJournalDo opts $
\CliOpts{rawopts_=_rawopts,reportopts_=ropts} j -> do
d <- getCurrentDay
let
q = queryFromOpts d ropts
ts = filter (q `matchesTransaction`) $ jtxns $ journalSelectingAmountFromOpts ropts j
tags = nub $ sort $ map fst $ concatMap transactionAllTags ts
mapM_ T.putStrLn tags
-- replace txns with date-swapped txns
-- print txns