Skip to content

Commit

Permalink
lib: add dropRawOpt, cliOptsDropArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichael committed Jan 22, 2025
1 parent 54e7a17 commit adef1a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions hledger-lib/Hledger/Data/RawOptions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Hledger.Data.RawOptions (
RawOpts,
mkRawOpts,
overRawOpts,
dropRawOpt,
setopt,
setboolopt,
unsetboolopt,
Expand Down Expand Up @@ -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)])

Expand Down
5 changes: 5 additions & 0 deletions hledger/Hledger/Cli/CliOptions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module Hledger.Cli.CliOptions (
getHledgerCliOpts,
getHledgerCliOpts',
rawOptsToCliOpts,
cliOptsDropArgs,
outputFormats,
defaultOutputFormat,
CommandHelpStr,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit adef1a8

Please sign in to comment.