imp:setup: improve output

This commit is contained in:
Simon Michael 2025-07-25 17:51:40 +01:00
parent 55f12d89e0
commit 6521b8dfdb

View File

@ -151,35 +151,37 @@ setupHledger = do
Just a | a /= arch -> p N $ "binary is for " <> a <> ", system is " <> arch <> ", may run slowly" Just a | a /= arch -> p N $ "binary is for " <> a <> ", system is " <> arch <> ", may run slowly"
Just a -> p Y a Just a -> p Y a
pdesc "is installed in PATH ?" pdesc "is installed in PATH (this version) ?"
pathexes <- findExecutables progname pathexes <- findExecutables progname
let msg = "To see more, please install this hledger in PATH and run hledger setup again." let
(failaction, failmsg) =
-- (exitFailure , "Please install this hledger in PATH then run setup again.")
(return () , " Some of this info may not apply to that hledger version. Continuing anyway..")
case pathexes of case pathexes of
[] -> p N msg >> exitFailure [] -> p N failmsg >> failaction
exe:_ -> do exe:_ -> do
eerrout <- tryHledgerArgs [["--version", "--no-conf"], ["--version"]] eerrout <- tryHledgerArgs [["--version", "--no-conf"], ["--version"]]
case eerrout of case eerrout of
Left err -> p U (progname <> " --version failed: " <> err) >> exitFailure Left err -> p U (progname <> " --version failed: " <> err) >> failaction
Right out -> do Right out -> do
case parseHledgerVersion out of case parseHledgerVersion out of
Left _ -> p U ("couldn't parse " <> progname <> " --version: " <> rstrip out) >> exitFailure Left _ -> p U ("couldn't parse " <> progname <> " --version: " <> rstrip out) >> exitFailure
Right pathbin -> do Right pathbin -> do
let pathversion = hbinVersionOutput pathbin let pathversion = hbinVersionOutput pathbin
if pathversion /= prognameandversion if pathversion /= prognameandversion
then p N (unlines [ then p N (chomp $ unlines [
"" ""
,"found in PATH: " <> exe ," A different hledger version was found in PATH: " <> pathversion
,"PATH hledger is: " <> pathversion ," at: " <> exe
,"this hledger is: " <> prognameandversion ,failmsg
,msg ]) >> failaction
]) >> exitFailure
else p Y exe else p Y exe
pdesc "has a system text encoding configured ?" pdesc "has a system text encoding configured ?"
let encoding = localeEncoding -- the initial system encoding let encoding = localeEncoding -- the initial system encoding
if map toLower (show encoding) == "ascii" if map toLower (show encoding) == "ascii"
then p N (show encoding <> ", please configure an encoding for non-ascii data") then p N (show encoding <> ", please configure an encoding for non-ascii data")
else p Y (show encoding <> ", data files should use this encoding") else p Y (show encoding <> ", data files must use this encoding")
-- pdesc "can handle UTF-8 text ?" -- pdesc "can handle UTF-8 text ?"
-- let -- let
@ -192,33 +194,29 @@ setupHledger = do
-- pdesc "can report text decoding failures ?" -- pdesc "can report text decoding failures ?"
-- i U (T.unpack $ T.decodeUtf8 eAcuteLatin1) -- i U (T.unpack $ T.decodeUtf8 eAcuteLatin1)
pdesc "has a user config file ? (optional)" pdesc "has a user config file ?"
muf <- activeUserConfFile muf <- activeUserConfFile
mlf <- activeLocalConfFile
let let
(ok, msg) = case muf of (ok, msg) = case muf of
Just f -> (Y, f <> if isJust mlf then " (overridden)" else "")
Nothing -> (N, "")
i ok msg
pdesc "has a local config file ?"
let
(ok, msg) = case mlf of
Just f -> (Y, f) Just f -> (Y, f)
Nothing -> (N, "") Nothing -> (N, "")
i ok msg i ok msg
pdesc "current directory has a local config ?"
mlf <- activeLocalConfFile
let
(ok, msg) = case mlf of
Just f -> (Y, f) -- <> if isJust muf then " (masking user config)" else "")
Nothing -> (N, "")
i ok msg
when (isJust muf && isJust mlf) $ do
pdesc "local config is masking user config ?"
i Y ""
if (isJust muf || isJust mlf) then do if (isJust muf || isJust mlf) then do
pdesc "the config file is readable ?" pdesc "the config file is readable ?"
econf <- getConf def econf <- getConf def
case econf of case econf of
Left e -> p N e >> return (Just $ Left e) Left e -> p N e >> return (Just $ Left e)
Right (conf, f) -> do Right (conf, _) -> do
p Y (fromMaybe "" f) p Y ""
-- pdesc "common general options are configured ?" -- pdesc "common general options are configured ?"
-- --infer-costs" -- --infer-costs"