diff options
author | eric thul <thul.eric@gmail.com> | 2015-07-05 10:13:47 -0400 |
---|---|---|
committer | eric thul <thul.eric@gmail.com> | 2015-07-06 23:53:01 -0400 |
commit | 1983893bf09a5c2ea1946e156be5da170075af7e (patch) | |
tree | f99bda0c0ff3c50356d8ab152336ba461c292494 /src/Options.purs | |
parent | 4558c6cf7879207166b1cc013e2e8112f558bb1d (diff) | |
download | purs-loader-1983893bf09a5c2ea1946e156be5da170075af7e.tar.gz purs-loader-1983893bf09a5c2ea1946e156be5da170075af7e.tar.zst purs-loader-1983893bf09a5c2ea1946e156be5da170075af7e.zip |
Updating for PureScript 0.7
Resolves #14
Diffstat (limited to 'src/Options.purs')
-rw-r--r-- | src/Options.purs | 46 |
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 @@ | |||
1 | module PursLoader.Options | 1 | module PursLoader.Options |
2 | ( pscMakeOptions | 2 | ( pscOptions |
3 | , pscMakeDefaultOutput | ||
4 | , pscMakeOutputOption | ||
5 | , loaderSrcOption | 3 | , loaderSrcOption |
6 | ) where | 4 | ) where |
7 | 5 | ||
6 | import Data.Array (concat) | ||
8 | import Data.Either (either) | 7 | import Data.Either (either) |
9 | 8 | ||
10 | import Data.Foreign (Foreign(), F()) | 9 | import Data.Foreign (Foreign(), F()) |
11 | import Data.Foreign.Class (IsForeign, read, readProp) | 10 | import Data.Foreign.Class (IsForeign, read, readProp) |
12 | import Data.Foreign.NullOrUndefined (NullOrUndefined(), runNullOrUndefined) | 11 | import Data.Foreign.NullOrUndefined (NullOrUndefined(..), runNullOrUndefined) |
13 | 12 | ||
14 | import Data.Maybe (Maybe(..), maybe) | 13 | import Data.Maybe (Maybe(..), maybe, fromMaybe) |
15 | 14 | ||
16 | noPreludeOpt = "no-prelude" | 15 | noPreludeOpt = "no-prelude" |
17 | 16 | ||
@@ -29,9 +28,11 @@ commentsOpt = "comments" | |||
29 | 28 | ||
30 | noPrefixOpt = "no-prefix" | 29 | noPrefixOpt = "no-prefix" |
31 | 30 | ||
31 | requirePathOpt = "require-path" | ||
32 | |||
32 | srcOpt = "src" | 33 | srcOpt = "src" |
33 | 34 | ||
34 | pscMakeDefaultOutput = "output" | 35 | ffiOpt = "ffi" |
35 | 36 | ||
36 | newtype Options | 37 | newtype 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 | ||
48 | instance isForeignOptions :: IsForeign Options where | 51 | instance 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 | ||
68 | class LoaderOption a where | 75 | class LoaderOption a where |
69 | opt :: String -> NullOrUndefined a -> [String] | 76 | opt :: String -> NullOrUndefined a -> [String] |
70 | 77 | ||
71 | instance booleanLoaderOption :: LoaderOption Boolean where | 78 | instance 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 | ||
75 | instance stringLoaderOption :: LoaderOption String where | 81 | instance 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 | ||
79 | pscMakeOutputOption :: Foreign -> Maybe String | 84 | instance arrayLoaderOption :: (LoaderOption a) => LoaderOption [a] where |
80 | pscMakeOutputOption 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 | ||
84 | pscMakeOptions :: Foreign -> [String] | 88 | pscOptions :: Foreign -> [String] |
85 | pscMakeOptions query = either (const []) fold parsed | 89 | pscOptions 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 | ||
96 | loaderSrcOption :: Foreign -> Maybe [String] | 102 | loaderSrcOption :: Foreign -> Maybe [String] |
97 | loaderSrcOption query = either (const Nothing) | 103 | loaderSrcOption query = either (const Nothing) (\(Options a) -> runNullOrUndefined a.src) (read query) |
98 | (\(Options a) -> runNullOrUndefined a.src) | ||
99 | (read query) | ||