imp:setup: improve output and logic; show strictness config
This commit is contained in:
parent
45e449e97a
commit
8f46eca6ec
@ -88,19 +88,16 @@ setup _opts@CliOpts{rawopts_=_rawopts, reportspec_=_rspec} _ignoredj = do
|
|||||||
,warning "unknown"
|
,warning "unknown"
|
||||||
,bad "warning"
|
,bad "warning"
|
||||||
]
|
]
|
||||||
conf <- fromMaybe nullconf <$> setupHledger
|
meconf <- setupHledger
|
||||||
setupTerminal conf
|
setupTerminal meconf
|
||||||
setupJournal
|
setupJournal meconf
|
||||||
-- setupStrictness conf
|
|
||||||
putStr "\n"
|
putStr "\n"
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- | This first test group looks for a "hledger" executable in PATH;
|
-- Returns Nothing if no config file was found,
|
||||||
-- if found, tests it in various ways;
|
-- or Just the read error or config if it was found.
|
||||||
-- and if it ran successfully, returns the full --version output
|
setupHledger :: IO (Maybe (Either String Conf))
|
||||||
-- and the numeric Version parsed from that.
|
|
||||||
setupHledger :: IO (Maybe Conf)
|
|
||||||
setupHledger = do
|
setupHledger = do
|
||||||
pgroup "hledger"
|
pgroup "hledger"
|
||||||
|
|
||||||
@ -128,7 +125,7 @@ setupHledger = do
|
|||||||
|
|
||||||
pdesc "is installed in PATH ?"
|
pdesc "is installed in PATH ?"
|
||||||
pathexes <- findExecutables progname
|
pathexes <- findExecutables progname
|
||||||
let msg = "please install this hledger in PATH and run setup again"
|
let msg = "To see more, please install this hledger in PATH and run hledger setup again."
|
||||||
case pathexes of
|
case pathexes of
|
||||||
[] -> p N msg >> exitFailure
|
[] -> p N msg >> exitFailure
|
||||||
exe:_ -> do
|
exe:_ -> do
|
||||||
@ -143,8 +140,9 @@ setupHledger = do
|
|||||||
if pathversion /= prognameandversion
|
if pathversion /= prognameandversion
|
||||||
then p N (unlines [
|
then p N (unlines [
|
||||||
""
|
""
|
||||||
,"PATH hledger is " <> pathversion <> " (" <> exe <> ")"
|
,"found in PATH: " <> exe
|
||||||
,"this hledger is " <> prognameandversion
|
,"PATH hledger is: " <> pathversion
|
||||||
|
,"this hledger is: " <> prognameandversion
|
||||||
,msg
|
,msg
|
||||||
]) >> exitFailure
|
]) >> exitFailure
|
||||||
else p Y exe
|
else p Y exe
|
||||||
@ -152,8 +150,8 @@ setupHledger = do
|
|||||||
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 to handle non-ascii text")
|
then p N (show encoding <> ", please configure an encoding for non-ascii data")
|
||||||
else p Y (show encoding)
|
else p Y (show encoding <> ", data files should use this encoding")
|
||||||
|
|
||||||
-- pdesc "can handle UTF-8 text ?"
|
-- pdesc "can handle UTF-8 text ?"
|
||||||
-- let
|
-- let
|
||||||
@ -190,7 +188,7 @@ setupHledger = 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 (show e) >> return Nothing
|
Left e -> p N e >> return (Just $ Left e)
|
||||||
Right (conf, f) -> do
|
Right (conf, f) -> do
|
||||||
p Y (fromMaybe "" f)
|
p Y (fromMaybe "" f)
|
||||||
|
|
||||||
@ -198,14 +196,19 @@ setupHledger = do
|
|||||||
-- --infer-costs"
|
-- --infer-costs"
|
||||||
-- print --explicit --show-costs"
|
-- print --explicit --show-costs"
|
||||||
|
|
||||||
return $ Just conf
|
return $ Just $ Right conf
|
||||||
else
|
else
|
||||||
return Nothing
|
return Nothing
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
setupTerminal conf = do
|
setupTerminal meconf = do
|
||||||
pgroup "terminal"
|
pgroup "terminal"
|
||||||
|
let
|
||||||
|
-- Find the last opt/arg matched by a predicate in the general config, if there is one.
|
||||||
|
conflookup predicate = case meconf of
|
||||||
|
Just (Right conf) -> find predicate $ reverse $ confLookup "general" conf
|
||||||
|
_ -> Nothing
|
||||||
|
|
||||||
pdesc "the NO_COLOR variable is defined ?"
|
pdesc "the NO_COLOR variable is defined ?"
|
||||||
mnocolor <- lookupEnv "NO_COLOR"
|
mnocolor <- lookupEnv "NO_COLOR"
|
||||||
@ -214,10 +217,8 @@ setupTerminal conf = do
|
|||||||
Just _ -> i Y ""
|
Just _ -> i Y ""
|
||||||
|
|
||||||
meconfigcolor <- do
|
meconfigcolor <- do
|
||||||
pdesc "color is configured in the config file ?" -- we check the general section only
|
pdesc "--color is configured by config file ?"
|
||||||
let
|
let mcolorarg = conflookup (\a -> any (`isPrefixOf` a) ["--color", "--colour"])
|
||||||
confgenargs = confLookup "general" conf
|
|
||||||
mcolorarg = find (\a -> any (`isPrefixOf` a) ["--color", "--colour"]) confgenargs
|
|
||||||
case mcolorarg of
|
case mcolorarg of
|
||||||
Nothing -> i N "" >> return Nothing
|
Nothing -> i N "" >> return Nothing
|
||||||
Just a -> do
|
Just a -> do
|
||||||
@ -239,10 +240,8 @@ setupTerminal conf = do
|
|||||||
Nothing -> i N ""
|
Nothing -> i N ""
|
||||||
Just v -> i Y v
|
Just v -> i Y v
|
||||||
|
|
||||||
pdesc "pager is configured in the config file ?"
|
pdesc "--pager is configured by config file ?"
|
||||||
let
|
let mpagerarg = conflookup ("--pager" `isPrefixOf`)
|
||||||
confgenargs = confLookup "general" conf
|
|
||||||
mpagerarg = find ("--pager" `isPrefixOf`) confgenargs
|
|
||||||
meconfpager <- case mpagerarg of
|
meconfpager <- case mpagerarg of
|
||||||
Nothing -> i N "" >> return Nothing
|
Nothing -> i N "" >> return Nothing
|
||||||
Just a -> do
|
Just a -> do
|
||||||
@ -285,11 +284,8 @@ setupTerminal conf = do
|
|||||||
usecolor <- useColorOnStdout
|
usecolor <- useColorOnStdout
|
||||||
i (if usecolor then Y else N) ""
|
i (if usecolor then Y else N) ""
|
||||||
|
|
||||||
pdesc "--pretty is enabled in the config file ?"
|
pdesc "--pretty is enabled by config file ?"
|
||||||
let
|
if isJust $ conflookup ("--pretty"==)
|
||||||
confgenargs = confLookup "general" conf
|
|
||||||
confpretty = isJust $ find ("--pretty" ==) confgenargs
|
|
||||||
if confpretty
|
|
||||||
then p Y "tables will use box-drawing characters"
|
then p Y "tables will use box-drawing characters"
|
||||||
else i N "tables will use ASCII characters"
|
else i N "tables will use ASCII characters"
|
||||||
|
|
||||||
@ -298,9 +294,13 @@ setupTerminal conf = do
|
|||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
setupJournal :: IO (Either String Journal)
|
setupJournal meconf = do
|
||||||
setupJournal = do
|
|
||||||
pgroup "journal"
|
pgroup "journal"
|
||||||
|
let
|
||||||
|
-- Find the last opt/arg matched by a predicate in the general config, if there is one.
|
||||||
|
conflookup predicate = case meconf of
|
||||||
|
Just (Right conf) -> find predicate $ reverse $ confLookup "general" conf
|
||||||
|
_ -> Nothing
|
||||||
|
|
||||||
-- pdesc "a home directory journal file exists ?"
|
-- pdesc "a home directory journal file exists ?"
|
||||||
-- mh <- getHomeSafe
|
-- mh <- getHomeSafe
|
||||||
@ -344,9 +344,7 @@ setupJournal = do
|
|||||||
-- XXX can this ignore assertions and config files, like the above ?
|
-- XXX can this ignore assertions and config files, like the above ?
|
||||||
ej <- defaultJournalSafely
|
ej <- defaultJournalSafely
|
||||||
case ej of
|
case ej of
|
||||||
Left e -> do
|
Left e -> p N (jfile <> ":\n" <> show e)
|
||||||
p N (jfile <> ":\n" <> show e)
|
|
||||||
return $ Left e
|
|
||||||
Right j@Journal{..} -> do
|
Right j@Journal{..} -> do
|
||||||
p Y jfile
|
p Y jfile
|
||||||
|
|
||||||
@ -420,15 +418,19 @@ setupJournal = do
|
|||||||
then p Y (concatMap show accttypes)
|
then p Y (concatMap show accttypes)
|
||||||
else p N (concatMap show typesnotfound <> "not found; type: queries, bs/cf/is reports may not work")
|
else p N (concatMap show typesnotfound <> "not found; type: queries, bs/cf/is reports may not work")
|
||||||
|
|
||||||
return $ Right j
|
pdesc "balance assertions are checked ?"
|
||||||
|
let
|
||||||
|
ignoreassertions = isJust $ conflookup (\a -> any (==a) ["-I", "--ignore-assertions"])
|
||||||
|
strict = isJust $ conflookup (\a -> any (==a) ["-s", "--strict"])
|
||||||
|
if
|
||||||
|
| ignoreassertions && not strict -> i N "use -s to check assertions"
|
||||||
|
| not strict -> i Y "use -I to ignore assertions"
|
||||||
|
| otherwise -> i Y "can't ignore assertions (-s in config file)"
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
pdesc "commodities/accounts are checked ?"
|
||||||
|
if strict
|
||||||
setupStrictness = do
|
then i Y "commodities and accounts must be declared"
|
||||||
pgroup "strictness"
|
else i N "use -s to check commodities/accounts"
|
||||||
pdesc "balance assertions are checked by default ?"
|
|
||||||
-- ignore-assertions
|
|
||||||
pdesc "commodities/conversions/accounts are checked by default ?"
|
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user