dev: Hledger.Utils.IO: getFlag helper, like getOpt
This commit is contained in:
parent
0ea239503c
commit
01e0c34b85
@ -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.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user