fix: extend application of commodity style to prices (except precision) and make --commodity-style a general flag
This commit is contained in:
parent
4cfd3cb590
commit
c0fd79a40e
3
.gitignore
vendored
3
.gitignore
vendored
@ -73,10 +73,11 @@ old
|
|||||||
hledger/test/addons/hledger-*
|
hledger/test/addons/hledger-*
|
||||||
tools/generatejournal
|
tools/generatejournal
|
||||||
tools/simplebench
|
tools/simplebench
|
||||||
/examples/10*.journal
|
/examples/[1-9]0*.journal
|
||||||
*.webmanual.md
|
*.webmanual.md
|
||||||
*.m4-e
|
*.m4-e
|
||||||
stack*.yaml.lock
|
stack*.yaml.lock
|
||||||
|
bench
|
||||||
|
|
||||||
# hledger-web stuff
|
# hledger-web stuff
|
||||||
/config
|
/config
|
||||||
|
|||||||
@ -173,6 +173,9 @@ m4_define({{_reportingoptions_}}, {{
|
|||||||
: generate future transactions from [periodic transaction](hledger.html#periodic-transactions) rules, for the next 6 months or till report end date.
|
: generate future transactions from [periodic transaction](hledger.html#periodic-transactions) rules, for the next 6 months or till report end date.
|
||||||
In hledger-ui, also make ordinary future transactions visible.
|
In hledger-ui, also make ordinary future transactions visible.
|
||||||
|
|
||||||
|
`--commodity-style`
|
||||||
|
: Override the commodity style in the output for the specified commodity. For example 'EUR1.000,00'.
|
||||||
|
|
||||||
`--color=WHEN (or --colour=WHEN)`
|
`--color=WHEN (or --colour=WHEN)`
|
||||||
: Should color-supporting commands use ANSI color codes in text output.
|
: Should color-supporting commands use ANSI color codes in text output.
|
||||||
: 'auto' (default): whenever stdout seems to be a color-supporting terminal.
|
: 'auto' (default): whenever stdout seems to be a color-supporting terminal.
|
||||||
|
|||||||
@ -429,11 +429,18 @@ showAmountPriceDebug (Just (TotalPrice pa)) = " @@ " ++ showAmountDebug pa
|
|||||||
-- | Given a map of standard commodity display styles, apply the
|
-- | Given a map of standard commodity display styles, apply the
|
||||||
-- appropriate one to this amount. If there's no standard style for
|
-- appropriate one to this amount. If there's no standard style for
|
||||||
-- this amount's commodity, return the amount unchanged.
|
-- this amount's commodity, return the amount unchanged.
|
||||||
|
-- Also apply the style to the price (except for precision)
|
||||||
styleAmount :: M.Map CommoditySymbol AmountStyle -> Amount -> Amount
|
styleAmount :: M.Map CommoditySymbol AmountStyle -> Amount -> Amount
|
||||||
styleAmount styles a =
|
styleAmount styles a = styledAmount{aprice = stylePrice styles (aprice styledAmount)}
|
||||||
case M.lookup (acommodity a) styles of
|
where
|
||||||
Just s -> a{astyle=s}
|
styledAmount = case M.lookup (acommodity a) styles of
|
||||||
Nothing -> a
|
Just s -> a{astyle=s}
|
||||||
|
Nothing -> a
|
||||||
|
|
||||||
|
stylePrice :: M.Map CommoditySymbol AmountStyle -> Maybe AmountPrice -> Maybe AmountPrice
|
||||||
|
stylePrice styles (Just (UnitPrice a)) = Just (UnitPrice $ styleAmountExceptPrecision styles a)
|
||||||
|
stylePrice styles (Just (TotalPrice a)) = Just (TotalPrice $ styleAmountExceptPrecision styles a)
|
||||||
|
stylePrice _ _ = Nothing
|
||||||
|
|
||||||
-- | Like styleAmount, but keep the number of decimal places unchanged.
|
-- | Like styleAmount, but keep the number of decimal places unchanged.
|
||||||
styleAmountExceptPrecision :: M.Map CommoditySymbol AmountStyle -> Amount -> Amount
|
styleAmountExceptPrecision :: M.Map CommoditySymbol AmountStyle -> Amount -> Amount
|
||||||
|
|||||||
@ -24,7 +24,6 @@ module Hledger.Cli.CliOptions (
|
|||||||
reportflags,
|
reportflags,
|
||||||
-- outputflags,
|
-- outputflags,
|
||||||
outputFormatFlag,
|
outputFormatFlag,
|
||||||
commodityStyleFlag,
|
|
||||||
outputFileFlag,
|
outputFileFlag,
|
||||||
generalflagsgroup1,
|
generalflagsgroup1,
|
||||||
generalflagsgroup2,
|
generalflagsgroup2,
|
||||||
@ -208,6 +207,8 @@ reportflags = [
|
|||||||
])
|
])
|
||||||
|
|
||||||
-- general output-related
|
-- general output-related
|
||||||
|
,flagReq ["commodity-style", "c"] (\s opts -> Right $ setopt "commodity-style" s opts) "COMM"
|
||||||
|
"Override the commodity style in the output for the specified commodity. For example 'EUR1.000,00'."
|
||||||
|
|
||||||
-- This has special support in hledger-lib:colorOption, keep synced
|
-- This has special support in hledger-lib:colorOption, keep synced
|
||||||
,flagReq ["color","colour"] (\s opts -> Right $ setopt "color" s opts) "WHEN"
|
,flagReq ["color","colour"] (\s opts -> Right $ setopt "color" s opts) "WHEN"
|
||||||
@ -254,11 +255,6 @@ outputFileFlag = flagReq
|
|||||||
["output-file","o"] (\s opts -> Right $ setopt "output-file" s opts) "FILE"
|
["output-file","o"] (\s opts -> Right $ setopt "output-file" s opts) "FILE"
|
||||||
"write output to FILE. A file extension matching one of the above formats selects that format."
|
"write output to FILE. A file extension matching one of the above formats selects that format."
|
||||||
|
|
||||||
commodityStyleFlag :: Flag RawOpts
|
|
||||||
commodityStyleFlag = flagReq
|
|
||||||
["commodity-style", "c"] (\s opts -> Right $ setopt "commodity-style" s opts) "COMM"
|
|
||||||
("Override the commodity style in the output for the specified commodity. For example 'EUR1.000,00'.")
|
|
||||||
|
|
||||||
argsFlag :: FlagHelp -> Arg RawOpts
|
argsFlag :: FlagHelp -> Arg RawOpts
|
||||||
argsFlag = flagArg (\s opts -> Right $ setopt "args" s opts)
|
argsFlag = flagArg (\s opts -> Right $ setopt "args" s opts)
|
||||||
|
|
||||||
|
|||||||
@ -58,7 +58,6 @@ aregistermode = hledgerCommandMode
|
|||||||
)
|
)
|
||||||
,outputFormatFlag ["txt","csv","json"]
|
,outputFormatFlag ["txt","csv","json"]
|
||||||
,outputFileFlag
|
,outputFileFlag
|
||||||
,commodityStyleFlag
|
|
||||||
])
|
])
|
||||||
[generalflagsgroup1]
|
[generalflagsgroup1]
|
||||||
hiddenflags
|
hiddenflags
|
||||||
|
|||||||
@ -319,7 +319,6 @@ balancemode = hledgerCommandMode
|
|||||||
"show commodity symbols in a separate column, amounts as bare numbers, one row per commodity"
|
"show commodity symbols in a separate column, amounts as bare numbers, one row per commodity"
|
||||||
,outputFormatFlag ["txt","html","csv","json"]
|
,outputFormatFlag ["txt","html","csv","json"]
|
||||||
,outputFileFlag
|
,outputFileFlag
|
||||||
,commodityStyleFlag
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
[generalflagsgroup1]
|
[generalflagsgroup1]
|
||||||
|
|||||||
@ -41,7 +41,6 @@ printmode = hledgerCommandMode
|
|||||||
"show only newer-dated transactions added in each file since last run"
|
"show only newer-dated transactions added in each file since last run"
|
||||||
,outputFormatFlag ["txt","csv","json","sql"]
|
,outputFormatFlag ["txt","csv","json","sql"]
|
||||||
,outputFileFlag
|
,outputFileFlag
|
||||||
,commodityStyleFlag
|
|
||||||
])
|
])
|
||||||
[generalflagsgroup1]
|
[generalflagsgroup1]
|
||||||
hiddenflags
|
hiddenflags
|
||||||
|
|||||||
@ -52,7 +52,6 @@ registermode = hledgerCommandMode
|
|||||||
)
|
)
|
||||||
,outputFormatFlag ["txt","csv","json"]
|
,outputFormatFlag ["txt","csv","json"]
|
||||||
,outputFileFlag
|
,outputFileFlag
|
||||||
,commodityStyleFlag
|
|
||||||
])
|
])
|
||||||
[generalflagsgroup1]
|
[generalflagsgroup1]
|
||||||
hiddenflags
|
hiddenflags
|
||||||
|
|||||||
@ -89,7 +89,6 @@ compoundBalanceCommandMode CompoundBalanceCommandSpec{..} =
|
|||||||
"show commodity symbols in a separate column, amounts as bare numbers, one row per commodity"
|
"show commodity symbols in a separate column, amounts as bare numbers, one row per commodity"
|
||||||
,outputFormatFlag ["txt","html","csv","json"]
|
,outputFormatFlag ["txt","html","csv","json"]
|
||||||
,outputFileFlag
|
,outputFileFlag
|
||||||
,commodityStyleFlag
|
|
||||||
])
|
])
|
||||||
[generalflagsgroup1]
|
[generalflagsgroup1]
|
||||||
hiddenflags
|
hiddenflags
|
||||||
|
|||||||
@ -1447,10 +1447,14 @@ real-world feedback.
|
|||||||
|
|
||||||
## Commodity styles
|
## Commodity styles
|
||||||
|
|
||||||
The display style of a commodity/currence is inferred according to the rules
|
The display style of a commodity/currency is inferred according to the rules
|
||||||
described in [Commodity display style](#commodity-display-style). The
|
described in [Commodity display style](#commodity-display-style). The
|
||||||
inferred display style can be overriden by an optional `-c/--commodity-style`
|
inferred display style can be overridden by an optional `-c/--commodity-style`
|
||||||
option. For example, the following will override the display style for dollars.
|
option (Exceptions: as is the case for inferred styles,
|
||||||
|
[price amounts](#transaction-prices), and all amounts displayed by the
|
||||||
|
[`print`](#print) command, will be displayed with all of their decimal digits
|
||||||
|
visible, regardless of the specified precision). For example, the following will
|
||||||
|
override the display style for dollars.
|
||||||
```shell
|
```shell
|
||||||
$ hledger print -c '$1.000,0'
|
$ hledger print -c '$1.000,0'
|
||||||
```
|
```
|
||||||
|
|||||||
@ -47,3 +47,13 @@ $ hledger -f- print -c 'EUR 1.000,00' -c 'EUR 1,000.00'
|
|||||||
(a) EUR 1,234.00
|
(a) EUR 1,234.00
|
||||||
|
|
||||||
>= 0
|
>= 0
|
||||||
|
# Commodity styles are applied to quantity and price of a commodity (except for precision)
|
||||||
|
<
|
||||||
|
2021-09-12 buy A
|
||||||
|
(a) 1,234 A @ $ 1234,56
|
||||||
|
$ hledger -f- print -c '1,000.0 $' -c 'A 1000.0'
|
||||||
|
>
|
||||||
|
2021-09-12 buy A
|
||||||
|
(a) A 1.234 @ 1,234.56 $
|
||||||
|
|
||||||
|
>= 0
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user