diff options
author | Joris | 2015-09-01 09:52:24 +0200 |
---|---|---|
committer | Joris | 2015-09-01 09:52:24 +0200 |
commit | d528036eae405f335498b57c2907c9269dc1554a (patch) | |
tree | 9c5c3bf14c890022ffa6ac8e7cdac316d6c45a20 /src/CommandLineOptions.hs | |
parent | c1c9b1f6233a7316c8df8fa50efba14fa5b21660 (diff) | |
download | perfume-d528036eae405f335498b57c2907c9269dc1554a.tar.gz perfume-d528036eae405f335498b57c2907c9269dc1554a.tar.bz2 perfume-d528036eae405f335498b57c2907c9269dc1554a.zip |
Using a custom command line parser
Diffstat (limited to 'src/CommandLineOptions.hs')
-rw-r--r-- | src/CommandLineOptions.hs | 43 |
1 files changed, 14 insertions, 29 deletions
diff --git a/src/CommandLineOptions.hs b/src/CommandLineOptions.hs index 9f1a3c0..bb0ac8d 100644 --- a/src/CommandLineOptions.hs +++ b/src/CommandLineOptions.hs @@ -1,35 +1,20 @@ module CommandLineOptions - ( Sample(..) - , getOptions + ( parseOptions ) where -import Control.Applicative ((<$>), (<*>)) - -import Options.Applicative - -data Sample = Sample - { hello :: String - , quiet :: Bool +data Options = Options + { materials :: [String] + , ignoreMaterials :: [String] } -getOptions :: IO Sample -getOptions = - execParser $ info - (helper <*> sample) - ( fullDesc - <> progDesc "Print a greeting for TARGET" - <> header "hello - a test for optparse-applicative" - ) +parseOptions :: [String] -> Options +parseOptions args = + case splitWhere (== "--ignore") args of + (materials, ignoredMaterials) -> Options materials ignoredMaterials -sample :: Parser Sample -sample = - Sample - <$> strOption - ( long "name" - <> metavar "TARGET" - <> help "Target for the greeting" - ) - <*> switch - ( long "quiet" - <> help "Whether to be quiet" - ) +splitWhere :: (a -> Bool) -> [a] -> ([a], [a]) +splitWhere match (x:xs) | match x = ([], xs) +splitWhere match (x:xs) = + case (splitWhere match xs) of + (ys, zs) -> (x:ys, zs) +splitWhere _ [] = ([], []) |