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
|
-- * Command line parsing
|
||||||
progArgs,
|
progArgs,
|
||||||
|
getFlag,
|
||||||
getOpt,
|
getOpt,
|
||||||
parseYN,
|
parseYN,
|
||||||
parseYNA,
|
parseYNA,
|
||||||
@ -500,6 +501,15 @@ progArgs = unsafePerformIO getArgs
|
|||||||
-- a few cases involving --color (see useColorOnStdoutUnsafe)
|
-- a few cases involving --color (see useColorOnStdoutUnsafe)
|
||||||
-- --debug
|
-- --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.
|
-- | 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.
|
-- If the value is missing raise an error.
|
||||||
-- Concatenated short flags (-a -b written as -ab) are not supported.
|
-- Concatenated short flags (-a -b written as -ab) are not supported.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user