imp:setup: improve config file tests, run only when supported

This commit is contained in:
Simon Michael 2025-04-22 08:53:08 -10:00
parent 3e8f3a4506
commit 6b5be96d27

View File

@ -92,17 +92,20 @@ setup _opts@CliOpts{rawopts_=_rawopts, reportspec_=_rspec} _ignoredj = do
case mversion of
Nothing -> return ()
Just (_, version) -> do
when (supportsConfig version) setupConfig
setupConfig version
setupFile version
-- setupAccounts version
-- setupCommodities version
-- setupTags version
return ()
putStr "\n"
supportsIgnoreAssertions = (>= 0 :| [24]) -- hledger 0.24+ supports --ignore-assertions
supportsConfig = (>= 1 :| [40]) -- hledger 1.40+ supports config files
-- Test a hledger version for support of various features.
supportsIgnoreAssertions = (>= 0 :| [24]) -- --ignore-assertions, 2014
supportsAccountTypes = (>= 1 :| [13]) -- ALERX account types, type: tag, 2019
supportsCashAccountType = (>= 1 :| [19]) -- C/Cash account type, 2020
supportsConversionAccountType = (>= 1 :| [25]) -- V/Conversion account type, accounts --types, 2022
supportsConfigFiles = (>= 1 :| [40]) -- config files, 2024
------------------------------------------------------------------------------
@ -205,9 +208,15 @@ setupHledger = do
------------------------------------------------------------------------------
setupConfig = do
setupConfig version = do
pgroup "config"
pdesc "this hledger supports config files ?"
if (not $ supportsConfigFiles version)
then p N "hledger 1.40+ needed"
else do
p Y ""
pdesc "a user config file exists ? (optional)"
muf <- activeUserConfFile
let
@ -303,7 +312,7 @@ setupFile version = do
args = concat [
["print"],
["--ignore-assertions" | supportsIgnoreAssertions version],
["--no-conf" | supportsConfig version]
["--no-conf" | supportsConfigFiles version]
]
(exit, _, err) <- readProcessWithExitCode progname args ""
case exit of