From adef1a8416262edbdab9e063a961b6d34d4065df Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 21 Jan 2025 22:02:05 -1000 Subject: [PATCH] lib: add dropRawOpt, cliOptsDropArgs --- hledger-lib/Hledger/Data/RawOptions.hs | 4 ++++ hledger/Hledger/Cli/CliOptions.hs | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/hledger-lib/Hledger/Data/RawOptions.hs b/hledger-lib/Hledger/Data/RawOptions.hs index 17b52058e34..ff63f023d0c 100644 --- a/hledger-lib/Hledger/Data/RawOptions.hs +++ b/hledger-lib/Hledger/Data/RawOptions.hs @@ -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)]) diff --git a/hledger/Hledger/Cli/CliOptions.hs b/hledger/Hledger/Cli/CliOptions.hs index 057264c07ac..8efbf0edc1b 100644 --- a/hledger/Hledger/Cli/CliOptions.hs +++ b/hledger/Hledger/Cli/CliOptions.hs @@ -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