aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoris2015-09-01 09:52:24 +0200
committerJoris2015-09-01 09:52:24 +0200
commitd528036eae405f335498b57c2907c9269dc1554a (patch)
tree9c5c3bf14c890022ffa6ac8e7cdac316d6c45a20
parentc1c9b1f6233a7316c8df8fa50efba14fa5b21660 (diff)
downloadperfume-d528036eae405f335498b57c2907c9269dc1554a.tar.gz
perfume-d528036eae405f335498b57c2907c9269dc1554a.tar.bz2
perfume-d528036eae405f335498b57c2907c9269dc1554a.zip
Using a custom command line parser
-rw-r--r--src/CommandLineOptions.hs43
-rw-r--r--src/Main.hs2
2 files changed, 16 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 _ [] = ([], [])
diff --git a/src/Main.hs b/src/Main.hs
index 94a075f..72e580d 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -18,6 +18,8 @@ import qualified Data.Text.IO as T
import Data.Text.Encoding (encodeUtf8)
import Data.Aeson (eitherDecodeStrict)
+import CommandLineOptions (parseOptions)
+
import Model.URL
import Model.Json.Search
import Model.Perfume