lib: add dropRawOpt, cliOptsDropArgs

This commit is contained in:
Simon Michael 2025-01-21 22:02:05 -10:00
parent 54e7a178b3
commit adef1a8416
2 changed files with 9 additions and 0 deletions

View File

@ -11,6 +11,7 @@ module Hledger.Data.RawOptions (
RawOpts,
mkRawOpts,
overRawOpts,
dropRawOpt,
setopt,
setboolopt,
unsetboolopt,
@ -53,6 +54,9 @@ mkRawOpts = RawOpts
overRawOpts :: ([(String,String)] -> [(String,String)]) -> RawOpts -> RawOpts
overRawOpts f = RawOpts . f . unRawOpts
dropRawOpt :: String -> RawOpts -> RawOpts
dropRawOpt a = overRawOpts $ filter (not.(==a).fst)
setopt :: String -> String -> RawOpts -> RawOpts
setopt name val = overRawOpts (++ [(name, val)])

View File

@ -58,6 +58,7 @@ module Hledger.Cli.CliOptions (
getHledgerCliOpts,
getHledgerCliOpts',
rawOptsToCliOpts,
cliOptsDropArgs,
outputFormats,
defaultOutputFormat,
CommandHelpStr,
@ -641,6 +642,10 @@ rawOptsToCliOpts rawopts = do
,available_width_ = availablewidth
}
-- | Drop the arguments ("args") from this CliOpts' rawopts field.
cliOptsDropArgs :: CliOpts -> CliOpts
cliOptsDropArgs copts@CliOpts{rawopts_} = copts{rawopts_ = dropRawOpt "args" rawopts_}
-- | A helper for addon commands: this parses options and arguments from
-- the current command line using the given hledger-style cmdargs mode,
-- and returns a CliOpts. Or, with --help or -h present, it prints