aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Options.purs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Options.purs')
-rw-r--r--src/Options.purs46
1 files changed, 25 insertions, 21 deletions
diff --git a/src/Options.purs b/src/Options.purs
index c47bebc..be21877 100644
--- a/src/Options.purs
+++ b/src/Options.purs
@@ -1,17 +1,16 @@
1module PursLoader.Options 1module PursLoader.Options
2 ( pscMakeOptions 2 ( pscOptions
3 , pscMakeDefaultOutput
4 , pscMakeOutputOption
5 , loaderSrcOption 3 , loaderSrcOption
6 ) where 4 ) where
7 5
6import Data.Array (concat)
8import Data.Either (either) 7import Data.Either (either)
9 8
10import Data.Foreign (Foreign(), F()) 9import Data.Foreign (Foreign(), F())
11import Data.Foreign.Class (IsForeign, read, readProp) 10import Data.Foreign.Class (IsForeign, read, readProp)
12import Data.Foreign.NullOrUndefined (NullOrUndefined(), runNullOrUndefined) 11import Data.Foreign.NullOrUndefined (NullOrUndefined(..), runNullOrUndefined)
13 12
14import Data.Maybe (Maybe(..), maybe) 13import Data.Maybe (Maybe(..), maybe, fromMaybe)
15 14
16noPreludeOpt = "no-prelude" 15noPreludeOpt = "no-prelude"
17 16
@@ -29,9 +28,11 @@ commentsOpt = "comments"
29 28
30noPrefixOpt = "no-prefix" 29noPrefixOpt = "no-prefix"
31 30
31requirePathOpt = "require-path"
32
32srcOpt = "src" 33srcOpt = "src"
33 34
34pscMakeDefaultOutput = "output" 35ffiOpt = "ffi"
35 36
36newtype Options 37newtype Options
37 = Options { noPrelude :: NullOrUndefined Boolean 38 = Options { noPrelude :: NullOrUndefined Boolean
@@ -42,7 +43,9 @@ newtype Options
42 , comments :: NullOrUndefined Boolean 43 , comments :: NullOrUndefined Boolean
43 , output :: NullOrUndefined String 44 , output :: NullOrUndefined String
44 , noPrefix :: NullOrUndefined Boolean 45 , noPrefix :: NullOrUndefined Boolean
46 , requirePath :: NullOrUndefined String
45 , src :: NullOrUndefined [String] 47 , src :: NullOrUndefined [String]
48 , ffi :: NullOrUndefined [String]
46 } 49 }
47 50
48instance isForeignOptions :: IsForeign Options where 51instance isForeignOptions :: IsForeign Options where
@@ -54,7 +57,9 @@ instance isForeignOptions :: IsForeign Options where
54 , comments: _ 57 , comments: _
55 , output: _ 58 , output: _
56 , noPrefix: _ 59 , noPrefix: _
60 , requirePath: _
57 , src: _ 61 , src: _
62 , ffi: _
58 } <$> readProp noPreludeOpt obj 63 } <$> readProp noPreludeOpt obj
59 <*> readProp noOptsOpt obj 64 <*> readProp noOptsOpt obj
60 <*> readProp noMagicDoOpt obj 65 <*> readProp noMagicDoOpt obj
@@ -63,26 +68,25 @@ instance isForeignOptions :: IsForeign Options where
63 <*> readProp commentsOpt obj 68 <*> readProp commentsOpt obj
64 <*> readProp outputOpt obj 69 <*> readProp outputOpt obj
65 <*> readProp noPrefixOpt obj 70 <*> readProp noPrefixOpt obj
66 <*> readProp srcOpt obj) 71 <*> readProp requirePathOpt obj
72 <*> readProp srcOpt obj
73 <*> readProp ffiOpt obj)
67 74
68class LoaderOption a where 75class LoaderOption a where
69 opt :: String -> NullOrUndefined a -> [String] 76 opt :: String -> NullOrUndefined a -> [String]
70 77
71instance booleanLoaderOption :: LoaderOption Boolean where 78instance booleanLoaderOption :: LoaderOption Boolean where
72 opt key opt = maybe [] (\a -> if a then ["--" ++ key] else []) 79 opt key val = maybe [] (\a -> if a then ["--" ++ key] else []) (runNullOrUndefined val)
73 (runNullOrUndefined opt)
74 80
75instance stringLoaderOption :: LoaderOption String where 81instance stringLoaderOption :: LoaderOption String where
76 opt key opt = maybe [] (\a -> ["--" ++ key ++ "=" ++ a]) 82 opt key val = maybe [] (\a -> ["--" ++ key ++ "=" ++ a]) (runNullOrUndefined val)
77 (runNullOrUndefined opt)
78 83
79pscMakeOutputOption :: Foreign -> Maybe String 84instance arrayLoaderOption :: (LoaderOption a) => LoaderOption [a] where
80pscMakeOutputOption query = either (const Nothing) 85 opt key val = concat (opt key <$> (NullOrUndefined <<< Just)
81 (\(Options a) -> runNullOrUndefined a.output) 86 <$> (fromMaybe [] (runNullOrUndefined val)))
82 (read query)
83 87
84pscMakeOptions :: Foreign -> [String] 88pscOptions :: Foreign -> [String]
85pscMakeOptions query = either (const []) fold parsed 89pscOptions query = either (const []) fold parsed
86 where parsed = read query :: F Options 90 where parsed = read query :: F Options
87 fold (Options a) = opt noPreludeOpt a.noPrelude <> 91 fold (Options a) = opt noPreludeOpt a.noPrelude <>
88 opt noOptsOpt a.noOpts <> 92 opt noOptsOpt a.noOpts <>
@@ -91,9 +95,9 @@ pscMakeOptions query = either (const []) fold parsed
91 opt verboseErrorsOpt a.verboseErrors <> 95 opt verboseErrorsOpt a.verboseErrors <>
92 opt commentsOpt a.comments <> 96 opt commentsOpt a.comments <>
93 opt outputOpt a.output <> 97 opt outputOpt a.output <>
94 opt noPrefixOpt a.noPrefix 98 opt noPrefixOpt a.noPrefix <>
99 opt requirePathOpt a.requirePath <>
100 opt ffiOpt a.ffi
95 101
96loaderSrcOption :: Foreign -> Maybe [String] 102loaderSrcOption :: Foreign -> Maybe [String]
97loaderSrcOption query = either (const Nothing) 103loaderSrcOption query = either (const Nothing) (\(Options a) -> runNullOrUndefined a.src) (read query)
98 (\(Options a) -> runNullOrUndefined a.src)
99 (read query)