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.