From 01e0c34b850855f35555dda1873ba149a05f76ea Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 17 Jul 2025 07:51:05 -0700 Subject: [PATCH] dev: Hledger.Utils.IO: getFlag helper, like getOpt --- hledger-lib/Hledger/Utils/IO.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hledger-lib/Hledger/Utils/IO.hs b/hledger-lib/Hledger/Utils/IO.hs index 0ad91e577..fea742dce 100644 --- a/hledger-lib/Hledger/Utils/IO.hs +++ b/hledger-lib/Hledger/Utils/IO.hs @@ -52,6 +52,7 @@ module Hledger.Utils.IO ( -- * Command line parsing progArgs, + getFlag, getOpt, parseYN, parseYNA, @@ -500,6 +501,15 @@ progArgs = unsafePerformIO getArgs -- a few cases involving --color (see useColorOnStdoutUnsafe) -- --debug +-- | Given one or more long or short flag names, +-- report whether this flag is present in the command line. +-- Concatenated short flags (-a -b written as -ab) are not supported. +getFlag :: [String] -> IO Bool +getFlag names = do + let flags = map toFlag names + args <- getArgs + return $ any (`elem` args) flags + -- | Given one or more long or short option names, read the rightmost value of this option from the command line arguments. -- If the value is missing raise an error. -- Concatenated short flags (-a -b written as -ab) are not supported.