prices: update for latest options/help style
This commit is contained in:
		
							parent
							
								
									66e33e0b0a
								
							
						
					
					
						commit
						9f8e96d189
					
				| @ -1,30 +1,35 @@ | |||||||
| #!/usr/bin/env stack | #!/usr/bin/env stack | ||||||
| {- stack runghc --verbosity info | {- stack runghc --verbosity info | ||||||
|   --package hledger |    --package hledger | ||||||
|  |    --package here | ||||||
| -} | -} | ||||||
| 
 | 
 | ||||||
|  | {-# LANGUAGE QuasiQuotes #-} | ||||||
|  | 
 | ||||||
| import Data.Maybe | import Data.Maybe | ||||||
|  | import Data.String.Here | ||||||
| import Data.Time | import Data.Time | ||||||
| import qualified Data.Text as T | import qualified Data.Text as T | ||||||
| import Control.Monad | import Control.Monad | ||||||
| import Hledger.Cli | import Hledger.Cli | ||||||
| 
 | 
 | ||||||
| cmdmode :: Mode RawOpts | ------------------------------------------------------------------------------ | ||||||
| cmdmode = (defCommandMode ["hledger-prices"]) { | cmdmode = | ||||||
|      modeArgs = ([], Nothing) |   let m = defAddonCommandMode "hledger-prices" | ||||||
|     ,modeHelp = "print all prices from journal" |   in m { | ||||||
|     ,modeGroupFlags = Group { |    modeHelp = [here| | ||||||
|          groupNamed = [ | Print all prices from the journal. | ||||||
|              ("Input",     inputflags) |   |] | ||||||
|             ,("Misc",      helpflags) |   ,modeHelpSuffix=lines [here| | ||||||
|             ] |   |] | ||||||
|         ,groupHidden = [] |   ,modeArgs = ([], Nothing) | ||||||
|         ,groupUnnamed = [ |   ,modeGroupFlags = (modeGroupFlags m) { | ||||||
|              flagNone ["costs"] (setboolopt "costs") |      groupUnnamed = [ | ||||||
|                 "collect prices from postings" |       flagNone ["costs"] (setboolopt "costs") "print transaction prices from postings instead of market prices" | ||||||
|             ] |      ] | ||||||
|         } |   } | ||||||
|     } |   } | ||||||
|  | ------------------------------------------------------------------------------ | ||||||
| 
 | 
 | ||||||
| showPrice :: MarketPrice -> String | showPrice :: MarketPrice -> String | ||||||
| showPrice mp = unwords ["P", show $ mpdate mp, T.unpack . quoteCommoditySymbolIfNeeded $ mpcommodity mp, showAmountWithZeroCommodity $ mpamount mp] | showPrice mp = unwords ["P", show $ mpdate mp, T.unpack . quoteCommoditySymbolIfNeeded $ mpcommodity mp, showAmountWithZeroCommodity $ mpamount mp] | ||||||
| @ -47,7 +52,7 @@ allPostsings = concatMap tpostings . jtxns | |||||||
| 
 | 
 | ||||||
| main :: IO () | main :: IO () | ||||||
| main = do | main = do | ||||||
|     opts <- getCliOpts cmdmode |     opts <- getHledgerCliOpts cmdmode | ||||||
|     withJournalDo opts{ ignore_assertions_ = True } $ \_ j -> do |     withJournalDo opts{ ignore_assertions_ = True } $ \_ j -> do | ||||||
|         let cprices = concatMap postingCosts . allPostsings $ j |         let cprices = concatMap postingCosts . allPostsings $ j | ||||||
|             printPrices = mapM_ (putStrLn . showPrice) |             printPrices = mapM_ (putStrLn . showPrice) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user