mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-28 21:02:04 +03:00
bin: add hledger-swap-dates
This commit is contained in:
parent
bc95f39757
commit
8bdcd9b38c
@ -10,6 +10,7 @@ They are:
|
|||||||
|
|
||||||
- hledger-check.hs - check more complex account balance assertions
|
- hledger-check.hs - check more complex account balance assertions
|
||||||
- hledger-smooth.hs - an attempt at automatically splitting infrequent/irregular transactions
|
- 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 :
|
A reminder from http://hledger.org/hledger.html#add-on-commands :
|
||||||
when using the main hledger executable to run add-on commands, remember
|
when using the main hledger executable to run add-on commands, remember
|
||||||
|
42
bin/hledger-swap-dates.hs
Executable file
42
bin/hledger-swap-dates.hs
Executable 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
|
Loading…
Reference in New Issue
Block a user