bin: hledger-swap-dates: update for latest hledger-lib, finish (#1072)
[ci skip]
This commit is contained in:
		
							parent
							
								
									cfb32a89d6
								
							
						
					
					
						commit
						acd6e5bfe3
					
				| @ -6,8 +6,10 @@ | |||||||
|    --package text |    --package text | ||||||
| -} | -} | ||||||
| 
 | 
 | ||||||
| {-# LANGUAGE QuasiQuotes #-} |  | ||||||
| {-# OPTIONS_GHC -Wno-missing-signatures -Wno-name-shadowing #-} | {-# OPTIONS_GHC -Wno-missing-signatures -Wno-name-shadowing #-} | ||||||
|  | {-# LANGUAGE NamedFieldPuns #-} | ||||||
|  | {-# LANGUAGE QuasiQuotes #-} | ||||||
|  | {-# LANGUAGE RecordWildCards #-} | ||||||
| 
 | 
 | ||||||
| import Data.List | import Data.List | ||||||
| import Data.String.Here | import Data.String.Here | ||||||
| @ -18,7 +20,8 @@ import Hledger.Cli | |||||||
| ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | ||||||
| cmdmode = hledgerCommandMode | cmdmode = hledgerCommandMode | ||||||
|   [here| swap-dates |   [here| swap-dates | ||||||
| Swap date and date2, on transactions and postings which have date2 defined. | Swap date and date2, on transactions which have date2 defined. | ||||||
|  | (Does not yet swap posting dates.) | ||||||
| FLAGS | FLAGS | ||||||
|   |] |   |] | ||||||
|   []  |   []  | ||||||
| @ -29,14 +32,16 @@ FLAGS | |||||||
| 
 | 
 | ||||||
| main :: IO () | main :: IO () | ||||||
| main = do | main = do | ||||||
|   opts <- getHledgerCliOpts cmdmode |   opts@CliOpts{reportopts_=ropts} <- getHledgerCliOpts cmdmode | ||||||
|   withJournalDo opts $ |   withJournalDo opts $ | ||||||
|    \CliOpts{rawopts_=_rawopts,reportopts_=ropts} j -> do |    \j -> do | ||||||
|     d <- getCurrentDay |     d <- getCurrentDay | ||||||
|     let |     let | ||||||
|       q = queryFromOpts d ropts |       q = queryFromOpts d ropts | ||||||
|       ts = filter (q `matchesTransaction`) $ jtxns $ journalSelectingAmountFromOpts ropts j |       ts = filter (q `matchesTransaction`) $ jtxns $ journalSelectingAmountFromOpts ropts j | ||||||
|       tags = nub $ sort $ map fst $ concatMap transactionAllTags ts |       ts' = map transactionSwapDates ts | ||||||
|     mapM_ T.putStrLn tags |     mapM_ (putStrLn . showTransactionUnelided) ts' | ||||||
|     -- replace txns with date-swapped txns | 
 | ||||||
|     -- print txns | transactionSwapDates :: Transaction -> Transaction | ||||||
|  | transactionSwapDates t@Transaction{tdate2=Nothing} = t | ||||||
|  | transactionSwapDates t@Transaction{tdate2=Just d} = t{tdate=d, tdate2=Just $ tdate t} | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user