aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/PursLoader/Options.purs
diff options
context:
space:
mode:
Diffstat (limited to 'src/PursLoader/Options.purs')
-rw-r--r--src/PursLoader/Options.purs16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/PursLoader/Options.purs b/src/PursLoader/Options.purs
index 51e9be5..e3957eb 100644
--- a/src/PursLoader/Options.purs
+++ b/src/PursLoader/Options.purs
@@ -4,6 +4,8 @@ module PursLoader.Options
4 , loaderFFIOption 4 , loaderFFIOption
5 ) where 5 ) where
6 6
7import Prelude (Unit(), (<>), (<$>), (<<<), (++), (<*>), const)
8
7import Data.Array (concat) 9import Data.Array (concat)
8import Data.Either (either) 10import Data.Either (either)
9 11
@@ -45,8 +47,8 @@ newtype Options
45 , output :: NullOrUndefined String 47 , output :: NullOrUndefined String
46 , noPrefix :: NullOrUndefined Boolean 48 , noPrefix :: NullOrUndefined Boolean
47 , requirePath :: NullOrUndefined String 49 , requirePath :: NullOrUndefined String
48 , src :: NullOrUndefined [String] 50 , src :: NullOrUndefined (Array String)
49 , ffi :: NullOrUndefined [String] 51 , ffi :: NullOrUndefined (Array String)
50 } 52 }
51 53
52instance isForeignOptions :: IsForeign Options where 54instance isForeignOptions :: IsForeign Options where
@@ -74,7 +76,7 @@ instance isForeignOptions :: IsForeign Options where
74 <*> readProp ffiOpt obj) 76 <*> readProp ffiOpt obj)
75 77
76class LoaderOption a where 78class LoaderOption a where
77 opt :: String -> NullOrUndefined a -> [String] 79 opt :: String -> NullOrUndefined a -> Array String
78 80
79instance booleanLoaderOption :: LoaderOption Boolean where 81instance booleanLoaderOption :: LoaderOption Boolean where
80 opt key val = maybe [] (\a -> if a then ["--" ++ key] else []) (runNullOrUndefined val) 82 opt key val = maybe [] (\a -> if a then ["--" ++ key] else []) (runNullOrUndefined val)
@@ -82,11 +84,11 @@ instance booleanLoaderOption :: LoaderOption Boolean where
82instance stringLoaderOption :: LoaderOption String where 84instance stringLoaderOption :: LoaderOption String where
83 opt key val = maybe [] (\a -> ["--" ++ key ++ "=" ++ a]) (runNullOrUndefined val) 85 opt key val = maybe [] (\a -> ["--" ++ key ++ "=" ++ a]) (runNullOrUndefined val)
84 86
85instance arrayLoaderOption :: (LoaderOption a) => LoaderOption [a] where 87instance arrayLoaderOption :: (LoaderOption a) => LoaderOption (Array a) where
86 opt key val = concat (opt key <$> (NullOrUndefined <<< Just) 88 opt key val = concat (opt key <$> (NullOrUndefined <<< Just)
87 <$> (fromMaybe [] (runNullOrUndefined val))) 89 <$> (fromMaybe [] (runNullOrUndefined val)))
88 90
89pscOptions :: Foreign -> [String] 91pscOptions :: Foreign -> Array String
90pscOptions query = either (const []) fold parsed 92pscOptions query = either (const []) fold parsed
91 where parsed = read query :: F Options 93 where parsed = read query :: F Options
92 fold (Options a) = opt noPreludeOpt a.noPrelude <> 94 fold (Options a) = opt noPreludeOpt a.noPrelude <>
@@ -100,8 +102,8 @@ pscOptions query = either (const []) fold parsed
100 opt requirePathOpt a.requirePath <> 102 opt requirePathOpt a.requirePath <>
101 opt ffiOpt a.ffi 103 opt ffiOpt a.ffi
102 104
103loaderSrcOption :: Foreign -> Maybe [String] 105loaderSrcOption :: Foreign -> Maybe (Array String)
104loaderSrcOption query = either (const Nothing) (\(Options a) -> runNullOrUndefined a.src) (read query) 106loaderSrcOption query = either (const Nothing) (\(Options a) -> runNullOrUndefined a.src) (read query)
105 107
106loaderFFIOption :: Foreign -> Maybe [String] 108loaderFFIOption :: Foreign -> Maybe (Array String)
107loaderFFIOption query = either (const Nothing) (\(Options a) -> runNullOrUndefined a.ffi) (read query) 109loaderFFIOption query = either (const Nothing) (\(Options a) -> runNullOrUndefined a.ffi) (read query)