imp:setup: improve config file tests, run only when supported
This commit is contained in:
parent
3e8f3a4506
commit
6b5be96d27
@ -92,17 +92,20 @@ setup _opts@CliOpts{rawopts_=_rawopts, reportspec_=_rspec} _ignoredj = do
|
|||||||
case mversion of
|
case mversion of
|
||||||
Nothing -> return ()
|
Nothing -> return ()
|
||||||
Just (_, version) -> do
|
Just (_, version) -> do
|
||||||
when (supportsConfig version) setupConfig
|
setupConfig version
|
||||||
setupFile version
|
setupFile version
|
||||||
-- setupAccounts version
|
-- setupAccounts version
|
||||||
-- setupCommodities version
|
-- setupCommodities version
|
||||||
-- setupTags version
|
-- setupTags version
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
putStr "\n"
|
putStr "\n"
|
||||||
|
|
||||||
supportsIgnoreAssertions = (>= 0 :| [24]) -- hledger 0.24+ supports --ignore-assertions
|
-- Test a hledger version for support of various features.
|
||||||
supportsConfig = (>= 1 :| [40]) -- hledger 1.40+ supports config files
|
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,43 +208,49 @@ setupHledger = do
|
|||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
setupConfig = do
|
setupConfig version = do
|
||||||
pgroup "config"
|
pgroup "config"
|
||||||
|
|
||||||
pdesc "a user config file exists ? (optional)"
|
pdesc "this hledger supports config files ?"
|
||||||
muf <- activeUserConfFile
|
if (not $ supportsConfigFiles version)
|
||||||
let
|
then p N "hledger 1.40+ needed"
|
||||||
(ok, msg) = case muf of
|
else do
|
||||||
Just f -> (Y, f)
|
p Y ""
|
||||||
Nothing -> (N, "")
|
|
||||||
i ok msg
|
|
||||||
|
|
||||||
pdesc "a local config file exists ?"
|
pdesc "a user config file exists ? (optional)"
|
||||||
mlf <- activeLocalConfFile
|
muf <- activeUserConfFile
|
||||||
let
|
let
|
||||||
(ok, msg) = case mlf of
|
(ok, msg) = case muf of
|
||||||
Just f -> (Y, f) -- <> if isJust muf then " (masking user config)" else "")
|
Just f -> (Y, f)
|
||||||
Nothing -> (N, "")
|
Nothing -> (N, "")
|
||||||
i ok msg
|
i ok msg
|
||||||
|
|
||||||
when (isJust muf && isJust mlf) $ do
|
pdesc "a local config file exists ?"
|
||||||
pdesc "local config is masking user config ?"
|
mlf <- activeLocalConfFile
|
||||||
i Y ""
|
let
|
||||||
|
(ok, msg) = case mlf of
|
||||||
|
Just f -> (Y, f) -- <> if isJust muf then " (masking user config)" else "")
|
||||||
|
Nothing -> (N, "")
|
||||||
|
i ok msg
|
||||||
|
|
||||||
let mf = mlf <|> muf
|
when (isJust muf && isJust mlf) $ do
|
||||||
case mf of
|
pdesc "local config is masking user config ?"
|
||||||
Nothing -> return ()
|
i Y ""
|
||||||
Just _ -> do
|
|
||||||
pdesc "this hledger can read the config file ?"
|
|
||||||
-- Test config file readability, without requiring journal file readability, forward compatibly.
|
|
||||||
(exit, _, err) <- readProcessWithExitCode progname ["print", "-f-"] ""
|
|
||||||
case exit of
|
|
||||||
ExitSuccess -> p Y ""
|
|
||||||
ExitFailure _ -> p N ("\n"<>err)
|
|
||||||
|
|
||||||
-- pdesc "common general options configured ?"
|
let mf = mlf <|> muf
|
||||||
-- --pretty --ignore-assertions --infer-costs"
|
case mf of
|
||||||
-- print --explicit --show-costs"
|
Nothing -> return ()
|
||||||
|
Just _ -> do
|
||||||
|
pdesc "this hledger can read the config file ?"
|
||||||
|
-- Test config file readability, without requiring journal file readability, forward compatibly.
|
||||||
|
(exit, _, err) <- readProcessWithExitCode progname ["print", "-f-"] ""
|
||||||
|
case exit of
|
||||||
|
ExitSuccess -> p Y ""
|
||||||
|
ExitFailure _ -> p N ("\n"<>err)
|
||||||
|
|
||||||
|
-- pdesc "common general options configured ?"
|
||||||
|
-- --pretty --ignore-assertions --infer-costs"
|
||||||
|
-- print --explicit --show-costs"
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -303,7 +312,7 @@ setupFile version = do
|
|||||||
args = concat [
|
args = concat [
|
||||||
["print"],
|
["print"],
|
||||||
["--ignore-assertions" | supportsIgnoreAssertions version],
|
["--ignore-assertions" | supportsIgnoreAssertions version],
|
||||||
["--no-conf" | supportsConfig version]
|
["--no-conf" | supportsConfigFiles version]
|
||||||
]
|
]
|
||||||
(exit, _, err) <- readProcessWithExitCode progname args ""
|
(exit, _, err) <- readProcessWithExitCode progname args ""
|
||||||
case exit of
|
case exit of
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user