cli: Commands.Aregister: new option --no-header
This commit is contained in:
parent
3714ac0593
commit
8a56c4944c
@ -28,7 +28,7 @@ import qualified Data.Map as Map
|
|||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Text.Lazy as TL
|
import qualified Data.Text.Lazy as TL
|
||||||
import qualified Data.Text.Lazy.Builder as TB
|
import qualified Data.Text.Lazy.Builder as TB
|
||||||
import Control.Monad (guard)
|
import Control.Monad (when)
|
||||||
import Lucid (toHtml)
|
import Lucid (toHtml)
|
||||||
import qualified Lucid as L
|
import qualified Lucid as L
|
||||||
import System.Console.CmdArgs.Explicit (flagNone, flagReq)
|
import System.Console.CmdArgs.Explicit (flagNone, flagReq)
|
||||||
@ -57,6 +57,8 @@ aregistermode = hledgerCommandMode
|
|||||||
-- "show running average of posting amounts instead of total (implies --empty)"
|
-- "show running average of posting amounts instead of total (implies --empty)"
|
||||||
-- ,flagNone ["related","r"] (setboolopt "related") "show postings' siblings instead"
|
-- ,flagNone ["related","r"] (setboolopt "related") "show postings' siblings instead"
|
||||||
-- ,flagNone ["invert"] (setboolopt "invert") "display all amounts with reversed sign"
|
-- ,flagNone ["invert"] (setboolopt "invert") "display all amounts with reversed sign"
|
||||||
|
,flagNone ["no-header"] (setboolopt "no-header")
|
||||||
|
"omit header row in table output"
|
||||||
,flagReq ["width","w"] (\s opts -> Right $ setopt "width" s opts) "N"
|
,flagReq ["width","w"] (\s opts -> Right $ setopt "width" s opts) "N"
|
||||||
("set output width (default: " ++
|
("set output width (default: " ++
|
||||||
#ifdef mingw32_HOST_OS
|
#ifdef mingw32_HOST_OS
|
||||||
@ -117,33 +119,36 @@ aregister opts@CliOpts{rawopts_=rawopts,reportspec_=rspec} j = do
|
|||||||
-- select renderer
|
-- select renderer
|
||||||
render | fmt=="txt" = accountTransactionsReportAsText opts (_rsQuery rspec') thisacctq
|
render | fmt=="txt" = accountTransactionsReportAsText opts (_rsQuery rspec') thisacctq
|
||||||
| fmt=="html" = accountTransactionsReportAsHTML opts (_rsQuery rspec') thisacctq
|
| fmt=="html" = accountTransactionsReportAsHTML opts (_rsQuery rspec') thisacctq
|
||||||
| fmt=="csv" = printCSV . accountTransactionsReportAsCsv wd (_rsQuery rspec') thisacctq
|
| fmt=="csv" = printCSV . accountTransactionsReportAsCsv hd wd (_rsQuery rspec') thisacctq
|
||||||
| fmt=="tsv" = printTSV . accountTransactionsReportAsCsv wd (_rsQuery rspec') thisacctq
|
| fmt=="tsv" = printTSV . accountTransactionsReportAsCsv hd wd (_rsQuery rspec') thisacctq
|
||||||
| fmt=="fods" =
|
| fmt=="fods" =
|
||||||
printFods IO.localeEncoding . Map.singleton "Aregister" .
|
printFods IO.localeEncoding . Map.singleton "Aregister" .
|
||||||
(,) (1,0) .
|
(,) (1,0) .
|
||||||
accountTransactionsReportAsSpreadsheet oneLineNoCostFmt wd (_rsQuery rspec') thisacctq
|
accountTransactionsReportAsSpreadsheet oneLineNoCostFmt hd wd (_rsQuery rspec') thisacctq
|
||||||
| fmt=="json" = toJsonText
|
| fmt=="json" = toJsonText
|
||||||
| otherwise = error' $ unsupportedOutputFormatError fmt -- PARTIAL:
|
| otherwise = error' $ unsupportedOutputFormatError fmt -- PARTIAL:
|
||||||
where
|
where
|
||||||
|
hd = headeropt opts
|
||||||
fmt = outputFormatFromOpts opts
|
fmt = outputFormatFromOpts opts
|
||||||
|
|
||||||
writeOutputLazyText opts $ render items'
|
writeOutputLazyText opts $ render items'
|
||||||
|
|
||||||
accountTransactionsReportAsCsv :: WhichDate -> Query -> Query -> AccountTransactionsReport -> CSV
|
accountTransactionsReportAsCsv ::
|
||||||
accountTransactionsReportAsCsv wd reportq thisacctq =
|
Bool -> WhichDate -> Query -> Query -> AccountTransactionsReport -> CSV
|
||||||
|
accountTransactionsReportAsCsv hd wd reportq thisacctq =
|
||||||
Spr.rawTableContent .
|
Spr.rawTableContent .
|
||||||
accountTransactionsReportAsSpreadsheet machineFmt wd reportq thisacctq
|
accountTransactionsReportAsSpreadsheet machineFmt hd wd reportq thisacctq
|
||||||
|
|
||||||
accountTransactionsReportAsSpreadsheet ::
|
accountTransactionsReportAsSpreadsheet ::
|
||||||
AmountFormat ->
|
AmountFormat -> Bool ->
|
||||||
WhichDate -> Query -> Query -> AccountTransactionsReport ->
|
WhichDate -> Query -> Query -> AccountTransactionsReport ->
|
||||||
[[Spr.Cell Spr.NumLines Text]]
|
[[Spr.Cell Spr.NumLines Text]]
|
||||||
accountTransactionsReportAsSpreadsheet fmt wd reportq thisacctq is =
|
accountTransactionsReportAsSpreadsheet fmt hd wd reportq thisacctq is =
|
||||||
Spr.addHeaderBorders
|
optional hd
|
||||||
(map Spr.headerCell
|
[Spr.addHeaderBorders $ map Spr.headerCell $
|
||||||
["txnidx","date","code","description","otheraccounts","change","balance"])
|
["txnidx","date","code","description","otheraccounts","change","balance"]]
|
||||||
: map (accountTransactionsReportItemAsRecord fmt True wd reportq thisacctq) is
|
++
|
||||||
|
map (accountTransactionsReportItemAsRecord fmt True wd reportq thisacctq) is
|
||||||
|
|
||||||
accountTransactionsReportItemAsRecord ::
|
accountTransactionsReportItemAsRecord ::
|
||||||
AmountFormat -> Bool ->
|
AmountFormat -> Bool ->
|
||||||
@ -152,9 +157,9 @@ accountTransactionsReportItemAsRecord ::
|
|||||||
accountTransactionsReportItemAsRecord
|
accountTransactionsReportItemAsRecord
|
||||||
fmt internals wd reportq thisacctq
|
fmt internals wd reportq thisacctq
|
||||||
(t@Transaction{tindex,tcode,tdescription}, _, _issplit, otheracctsstr, change, balance)
|
(t@Transaction{tindex,tcode,tdescription}, _, _issplit, otheracctsstr, change, balance)
|
||||||
= (guard internals >> [Spr.integerCell tindex]) ++
|
= (optional internals [Spr.integerCell tindex]) ++
|
||||||
date :
|
date :
|
||||||
(guard internals >> [cell tcode]) ++
|
(optional internals [cell tcode]) ++
|
||||||
[cell tdescription,
|
[cell tdescription,
|
||||||
cell otheracctsstr,
|
cell otheracctsstr,
|
||||||
amountCell change,
|
amountCell change,
|
||||||
@ -174,7 +179,7 @@ accountTransactionsReportAsHTML copts reportq thisacctq items =
|
|||||||
L.renderText $ do
|
L.renderText $ do
|
||||||
L.link_ [L.rel_ "stylesheet", L.href_ "hledger.css"]
|
L.link_ [L.rel_ "stylesheet", L.href_ "hledger.css"]
|
||||||
L.table_ $ do
|
L.table_ $ do
|
||||||
L.thead_ $ L.tr_ $ do
|
when (headeropt copts) $ L.thead_ $ L.tr_ $ do
|
||||||
L.th_ "date"
|
L.th_ "date"
|
||||||
L.th_ "description"
|
L.th_ "description"
|
||||||
L.th_ "otheraccounts"
|
L.th_ "otheraccounts"
|
||||||
@ -190,7 +195,8 @@ accountTransactionsReportAsHTML copts reportq thisacctq items =
|
|||||||
-- | Render a register report as plain text suitable for console output.
|
-- | Render a register report as plain text suitable for console output.
|
||||||
accountTransactionsReportAsText :: CliOpts -> Query -> Query -> AccountTransactionsReport -> TL.Text
|
accountTransactionsReportAsText :: CliOpts -> Query -> Query -> AccountTransactionsReport -> TL.Text
|
||||||
accountTransactionsReportAsText copts reportq thisacctq items = TB.toLazyText $
|
accountTransactionsReportAsText copts reportq thisacctq items = TB.toLazyText $
|
||||||
title <> TB.singleton '\n' <>
|
(optional (headeropt copts) $ title <> TB.singleton '\n')
|
||||||
|
<>
|
||||||
postingsOrTransactionsReportAsText alignAll copts itemAsText itemamt itembal items
|
postingsOrTransactionsReportAsText alignAll copts itemAsText itemamt itembal items
|
||||||
where
|
where
|
||||||
alignAll = boolopt "align-all" $ rawopts_ copts
|
alignAll = boolopt "align-all" $ rawopts_ copts
|
||||||
@ -212,6 +218,13 @@ accountTransactionsReportAsText copts reportq thisacctq items = TB.toLazyText $
|
|||||||
length (querystring_ $ _rsReportOpts $ reportspec_ copts) > 1
|
length (querystring_ $ _rsReportOpts $ reportspec_ copts) > 1
|
||||||
&& not (queryIsNull $ filterQuery (not.(\q->queryIsDepth q || queryIsDateOrDate2 q)) reportq)
|
&& not (queryIsNull $ filterQuery (not.(\q->queryIsDepth q || queryIsDateOrDate2 q)) reportq)
|
||||||
|
|
||||||
|
headeropt :: CliOpts -> Bool
|
||||||
|
headeropt = not . boolopt "no-header" . rawopts_
|
||||||
|
|
||||||
|
optional :: (Monoid p) => Bool -> p -> p
|
||||||
|
optional b x = if b then x else mempty
|
||||||
|
|
||||||
|
|
||||||
-- | Render one account register report line item as plain text. Layout is like so:
|
-- | Render one account register report line item as plain text. Layout is like so:
|
||||||
-- @
|
-- @
|
||||||
-- <---------------- width (specified, terminal width, or 80) -------------------->
|
-- <---------------- width (specified, terminal width, or 80) -------------------->
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user