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