From d528036eae405f335498b57c2907c9269dc1554a Mon Sep 17 00:00:00 2001 From: Joris Date: Tue, 1 Sep 2015 09:52:24 +0200 Subject: Using a custom command line parser --- src/CommandLineOptions.hs | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) (limited to 'src/CommandLineOptions.hs') 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 _ [] = ([], []) -- cgit v1.2.3