{-# LANGUAGE TemplateHaskell #-}
module Hledger.Cli.Commands.Transactions (
transactionsmode
,transactions
) where
import System.Console.CmdArgs.Explicit
import Hledger
import Hledger.Cli.CliOptions
import Hledger.Cli.Utils (withTitle, writeOutputLazyText)
import Hledger.Cli.Commands.Print (journalApplyMatchOpt, entriesReportAsTextHelper)
transactionsmode :: Mode RawOpts
transactionsmode = CommandHelpStr
-> [Flag RawOpts]
-> [(CommandHelpStr, [Flag RawOpts])]
-> [Flag RawOpts]
-> ([Arg RawOpts], Maybe (Arg RawOpts))
-> Mode RawOpts
hledgerCommandMode
$(embedFileRelative "Hledger/Cli/Commands/Transactions.txt")
[
let arg :: CommandHelpStr
arg = CommandHelpStr
"DESC" in
[CommandHelpStr]
-> Update RawOpts
-> CommandHelpStr
-> CommandHelpStr
-> Flag RawOpts
forall a.
[CommandHelpStr]
-> Update a -> CommandHelpStr -> CommandHelpStr -> Flag a
flagReq [CommandHelpStr
"match",CommandHelpStr
"m"] (\CommandHelpStr
s RawOpts
opts -> RawOpts -> Either CommandHelpStr RawOpts
forall a b. b -> Either a b
Right (RawOpts -> Either CommandHelpStr RawOpts)
-> RawOpts -> Either CommandHelpStr RawOpts
forall a b. (a -> b) -> a -> b
$ CommandHelpStr -> CommandHelpStr -> RawOpts -> RawOpts
setopt CommandHelpStr
"match" CommandHelpStr
s RawOpts
opts) CommandHelpStr
arg
(CommandHelpStr
"fuzzy search for one recent transaction with description closest to "CommandHelpStr -> CommandHelpStr -> CommandHelpStr
forall a. [a] -> [a] -> [a]
++CommandHelpStr
arg)
]
[(CommandHelpStr, [Flag RawOpts])]
cligeneralflagsgroups1
[Flag RawOpts]
hiddenflags
([], Arg RawOpts -> Maybe (Arg RawOpts)
forall a. a -> Maybe a
Just (Arg RawOpts -> Maybe (Arg RawOpts))
-> Arg RawOpts -> Maybe (Arg RawOpts)
forall a b. (a -> b) -> a -> b
$ CommandHelpStr -> Arg RawOpts
argsFlag CommandHelpStr
"[QUERY]")
transactions :: CliOpts -> Journal -> IO ()
transactions :: CliOpts -> Journal -> IO ()
transactions opts :: CliOpts
opts@CliOpts{reportspec_ :: CliOpts -> ReportSpec
reportspec_=ReportSpec
rspec} =
CliOpts -> Text -> IO ()
writeOutputLazyText CliOpts
opts
(Text -> IO ()) -> (Journal -> Text) -> Journal -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ReportOpts -> Text -> Text
withTitle (ReportSpec -> ReportOpts
_rsReportOpts ReportSpec
rspec)
(Text -> Text) -> (Journal -> Text) -> Journal -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Transaction -> Text) -> EntriesReport -> Text
entriesReportAsTextHelper Transaction -> Text
showTransactionOneLine
(EntriesReport -> Text)
-> (Journal -> EntriesReport) -> Journal -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ReportSpec -> Journal -> EntriesReport
entriesReport ReportSpec
rspec
(Journal -> EntriesReport)
-> (Journal -> Journal) -> Journal -> EntriesReport
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CliOpts -> Journal -> Journal
journalApplyMatchOpt CliOpts
opts