| 1 |
{-| |
| 2 |
|
| 3 |
The @codes@ command lists the codes seen in transactions, in the order parsed. |
| 4 |
|
| 5 |
-} |
| 6 |
|
| 7 |
{-# LANGUAGE MultiWayIf #-} |
| 8 |
{-# LANGUAGE NamedFieldPuns #-} |
| 9 |
{-# LANGUAGE OverloadedStrings #-} |
| 10 |
{-# LANGUAGE ScopedTypeVariables #-} |
| 11 |
{-# LANGUAGE TemplateHaskell #-} |
| 12 |
|
| 13 |
module Hledger.Cli.Commands.Codes ( |
| 14 |
codesmode |
| 15 |
,codes |
| 16 |
) where |
| 17 |
|
| 18 |
import Data.Text qualified as T |
| 19 |
import Data.Text.IO qualified as T |
| 20 |
|
| 21 |
import Hledger |
| 22 |
import Hledger.Cli.CliOptions |
| 23 |
|
| 24 |
|
| 25 |
-- | Command line options for this command. |
| 26 |
codesmode = hledgerCommandMode |
| 27 |
$(embedFileRelative "Hledger/Cli/Commands/Codes.txt") |
| 28 |
[] |
| 29 |
cligeneralflagsgroups1 |
| 30 |
hiddenflags |
| 31 |
([], Just $ argsFlag "[QUERY]") |
| 32 |
|
| 33 |
-- | The codes command. |
| 34 |
codes :: CliOpts -> Journal -> IO () |
| 35 |
codes CliOpts{reportspec_=rspec} j = do |
| 36 |
let ts = entriesReport rspec j |
| 37 |
codes' = (if empty_ (_rsReportOpts rspec) then id else filter (not . T.null)) $ |
| 38 |
map tcode ts |
| 39 |
mapM_ T.putStrLn codes' |