aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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