dev: cln: drop Hledger.Data.RawOptions.inRawOpts

This commit is contained in:
Simon Michael 2023-05-09 10:02:24 -10:00
parent a1da8f2899
commit 147d49c66c
5 changed files with 16 additions and 20 deletions

View File

@ -13,7 +13,6 @@ module Hledger.Data.RawOptions (
setboolopt,
unsetboolopt,
appendopts,
inRawOpts,
boolopt,
choiceopt,
collectopts,
@ -56,12 +55,9 @@ unsetboolopt name = overRawOpts (filter ((/=name).fst))
appendopts :: [(String,String)] -> RawOpts -> RawOpts
appendopts new = overRawOpts (++new)
-- | Is the named option present ?
inRawOpts :: String -> RawOpts -> Bool
inRawOpts name = isJust . lookup name . unRawOpts
-- | Is the named flag present ?
boolopt :: String -> RawOpts -> Bool
boolopt = inRawOpts
boolopt name = isJust . lookup name . unRawOpts
-- | From a list of RawOpts, get the last one (ie the right-most on the command line)
-- for which the given predicate returns a Just value.

View File

@ -72,11 +72,11 @@ main = withProgName "hledger-ui.log" $ do -- force Hledger.Utils.Debug.* to log
let copts' = copts{inputopts_=iopts{forecast_=forecast_ iopts <|> Just nulldatespan}}
case True of
_ | "help" `inRawOpts` rawopts -> pager (showModeUsage uimode)
_ | "info" `inRawOpts` rawopts -> runInfoForTopic "hledger-ui" Nothing
_ | "man" `inRawOpts` rawopts -> runManForTopic "hledger-ui" Nothing
_ | "version" `inRawOpts` rawopts -> putStrLn prognameandversion
-- _ | "binary-filename" `inRawOpts` rawopts -> putStrLn (binaryfilename progname)
_ | boolopt "help" rawopts -> pager (showModeUsage uimode)
_ | boolopt "info" rawopts -> runInfoForTopic "hledger-ui" Nothing
_ | boolopt "man" rawopts -> runManForTopic "hledger-ui" Nothing
_ | boolopt "version" rawopts -> putStrLn prognameandversion
-- _ | boolopt "binary-filename" rawopts -> putStrLn (binaryfilename progname)
_ -> withJournalDo copts' (runBrickUi opts)
runBrickUi :: UIOpts -> Journal -> IO ()

View File

@ -54,12 +54,12 @@ hledgerWebMain = do
wopts@WebOpts{cliopts_=copts@CliOpts{debug_, rawopts_}} <- getHledgerWebOpts
when (debug_ > 0) $ printf "%s\n" prognameandversion >> printf "opts: %s\n" (show wopts)
if
| "help" `inRawOpts` rawopts_ -> pager (showModeUsage webmode) >> exitSuccess
| "info" `inRawOpts` rawopts_ -> runInfoForTopic "hledger-web" Nothing
| "man" `inRawOpts` rawopts_ -> runManForTopic "hledger-web" Nothing
| "version" `inRawOpts` rawopts_ -> putStrLn prognameandversion >> exitSuccess
-- "binary-filename" `inRawOpts` rawopts_ -> putStrLn (binaryfilename progname)
| "test" `inRawOpts` rawopts_ -> do
| boolopt "help" rawopts_ -> pager (showModeUsage webmode) >> exitSuccess
| boolopt "info" rawopts_ -> runInfoForTopic "hledger-web" Nothing
| boolopt "man" rawopts_ -> runManForTopic "hledger-web" Nothing
| boolopt "version" rawopts_ -> putStrLn prognameandversion >> exitSuccess
-- boolopt "binary-filename" rawopts_ -> putStrLn (binaryfilename progname)
| boolopt "test" rawopts_ -> do
-- remove --test and --, leaving other args for hspec
(`withArgs` hledgerWebTest) . filter (`notElem` ["--test","--"]) =<< getArgs
| otherwise -> withJournalDo copts (web wopts)

View File

@ -575,8 +575,8 @@ getHledgerCliOpts' mode' args0 = do
let rawopts = either usageError id $ process mode' args0
opts <- rawOptsToCliOpts rawopts
debugArgs args0 opts
when ("help" `inRawOpts` rawopts_ opts) $ putStr shorthelp >> exitSuccess
-- when ("help" `inRawOpts` rawopts_ opts) $ putStr longhelp >> exitSuccess
when (boolopt "help" $ rawopts_ opts) $ putStr shorthelp >> exitSuccess
-- when (boolopt "help" $ rawopts_ opts) $ putStr longhelp >> exitSuccess
return opts
where
longhelp = showModeUsage mode'

View File

@ -174,7 +174,7 @@ main = do
| not (isExternalCommand || hasHelpFlag args || hasInfoFlag args || hasManFlag args)
&& (hasVersion args) -- || (hasVersion argsaftercmd && isInternalCommand))
= putStrLn prognameandversion
-- \| (null externalcmd) && "binary-filename" `inRawOpts` rawopts = putStrLn $ binaryfilename progname
-- \| (null externalcmd) && boolopt "binary-filename" rawopts = putStrLn $ binaryfilename progname
-- \| "--browse-args" `elem` args = System.Console.CmdArgs.Helper.execute "cmdargs-browser" mainmode' args >>= (putStr . show)
| isNullCommand = dbgIO "" "no command, showing commands list" >> printCommandsList prognameandversion addons
| isBadCommand = badCommandError