lib!: refactor, rename
pivotByOpts -> maybePivot anonymiseByOpts -> maybeWarnAboutAnon
This commit is contained in:
parent
e64c26e603
commit
c19620f3bc
@ -21,8 +21,8 @@ module Hledger.Cli.Utils
|
|||||||
openBrowserOn,
|
openBrowserOn,
|
||||||
writeFileWithBackup,
|
writeFileWithBackup,
|
||||||
writeFileWithBackupIfChanged,
|
writeFileWithBackupIfChanged,
|
||||||
pivotByOpts,
|
maybePivot,
|
||||||
anonymiseByOpts,
|
maybeWarnAboutAnon,
|
||||||
journalSimilarTransaction,
|
journalSimilarTransaction,
|
||||||
postingsOrTransactionsReportAsText,
|
postingsOrTransactionsReportAsText,
|
||||||
tests_Cli_Utils,
|
tests_Cli_Utils,
|
||||||
@ -80,33 +80,29 @@ withJournal opts cmd = do
|
|||||||
{-# DEPRECATED withJournalDo "renamed, please use withJournal instead" #-}
|
{-# DEPRECATED withJournalDo "renamed, please use withJournal instead" #-}
|
||||||
withJournalDo = withJournal
|
withJournalDo = withJournal
|
||||||
|
|
||||||
-- | Apply some extra post-parse transformations to the journal, if enabled by options.
|
-- | Apply some journal transformations, if enabled by options, that should happen late.
|
||||||
-- These happen after parsing and finalising the journal, but before report calculation.
|
-- These happen after parsing, finalising the journal, strict checks, and .latest filtering/updating,
|
||||||
-- They are, in processing order:
|
-- but before report calculation. They are, in processing order:
|
||||||
--
|
-- --pivot, --anonymise error message, --obfuscate.
|
||||||
-- - pivoting account names (--pivot)
|
|
||||||
--
|
|
||||||
-- - anonymising (--anonymise).
|
|
||||||
--
|
|
||||||
journalTransform :: CliOpts -> Journal -> Journal
|
journalTransform :: CliOpts -> Journal -> Journal
|
||||||
journalTransform opts =
|
journalTransform opts =
|
||||||
pivotByOpts opts
|
|
||||||
<&> anonymiseByOpts opts
|
|
||||||
<&> maybeObfuscate opts
|
|
||||||
-- XXX Called by withJournal, journalReload, uiReloadJournal, withJournalCached.
|
-- XXX Called by withJournal, journalReload, uiReloadJournal, withJournalCached.
|
||||||
-- Could it be moved down into journalFinalise ? These steps only depend on InputOpts.
|
-- Could it be moved down into journalFinalise ? These steps only depend on InputOpts.
|
||||||
|
maybePivot opts
|
||||||
|
<&> maybeWarnAboutAnon opts
|
||||||
|
<&> maybeObfuscate opts
|
||||||
|
|
||||||
-- | Apply the pivot transformation on a journal (replacing account names by a different field's value), if option is present.
|
-- | If the --pivot option is present, replace the journal's account names by specified other values.
|
||||||
pivotByOpts :: CliOpts -> Journal -> Journal
|
maybePivot :: CliOpts -> Journal -> Journal
|
||||||
pivotByOpts opts =
|
maybePivot opts =
|
||||||
case maybestringopt "pivot" . rawopts_ $ opts of
|
case maybestringopt "pivot" . rawopts_ $ opts of
|
||||||
Just tag -> journalPivot $ T.pack tag
|
Just tag -> journalPivot $ T.pack tag
|
||||||
Nothing -> id
|
Nothing -> id
|
||||||
|
|
||||||
-- #2133
|
-- #2133
|
||||||
-- | Raise an error, announcing the rename to --obfuscate and its limitations.
|
-- | If the --anon flag is present, raise an informative error.
|
||||||
anonymiseByOpts :: CliOpts -> Journal -> Journal
|
maybeWarnAboutAnon :: CliOpts -> Journal -> Journal
|
||||||
anonymiseByOpts opts =
|
maybeWarnAboutAnon opts =
|
||||||
if boolopt "anon" $ rawopts_ opts
|
if boolopt "anon" $ rawopts_ opts
|
||||||
then error' $ unlines [
|
then error' $ unlines [
|
||||||
"--anon does not give privacy, and perhaps should be avoided;"
|
"--anon does not give privacy, and perhaps should be avoided;"
|
||||||
@ -115,7 +111,7 @@ anonymiseByOpts opts =
|
|||||||
]
|
]
|
||||||
else id
|
else id
|
||||||
|
|
||||||
-- | Apply light obfuscation to a journal, if --obfuscate is present (formerly --anon).
|
-- | If the --obfuscate flag is present, apply light obfuscation to the journal data.
|
||||||
maybeObfuscate :: CliOpts -> Journal -> Journal
|
maybeObfuscate :: CliOpts -> Journal -> Journal
|
||||||
maybeObfuscate opts =
|
maybeObfuscate opts =
|
||||||
if anon_ . inputopts_ $ opts
|
if anon_ . inputopts_ $ opts
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user