git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add explicit import of Monoid <> (#2278)

* Use bind instead of deprecated bindSocket * Add explicit import of Monoid <> optparse-applicative 0.13.* no longer exports this. * Add charleso to contributors file * Import Options.Applicative as qualified for future proofing

commitbdbf4e28a3f734cf853b8a5a46d6441a4c17547b authorCharles O'Farrell <charleso@charleso.org> dateSun 21 Aug 2016, 12:03 (10 years ago) parent8968dc8
6 files changed+81−67
CONTRIBUTORS.md+1 hierarchy/Main.hs+18−15 psc-bundle/Main.hs+28−25 psc-ide-client/Main.hs+8−5 psc-ide-server/Main.hs+13−12 psc-publish/Main.hs+13−10
CONTRIBUTORS.md+1
@@ -16,6 +16,7 @@ This file lists the contributors to the PureScript compiler project, and the ter
1616- [@Bogdanp](https://github.com/Bogdanp) (Bogdan Paul Popa) My existing contributions and all future contributions until further notice are Copyright Bogdan Paul Popa, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
1717- [@bsermons](https://github.com/bsermons) (Brian Sermons) My existing contributions and all future contributions until further notice are Copyright Brian Sermons, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
1818- [@cdepillabout](https://github.com/cdepillabout) (Dennis Gosnell) My existing contributions and all future contributions until further notice are Copyright Dennis Gosnell, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
19+- [@charleso](https://github.com/charleso) (Charles O'Farrell) My existing contributions to the PureScript compiler and all future contributions to the PureScript compiler until further notice, are Copyright Charles O'Farrell, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
1920- [@chrissmoak](https://github.com/chrissmoak) (Chris Smoak) My existing contributions to the PureScript compiler and all future contributions to the PureScript compiler until further notice, are Copyright Chris Smoak, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
2021- [@codedmart](https://github.com/codedmart) (Brandon Martin) My existing contributions and all future contributions until further notice are Copyright Brandon Martin, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
2122- [@davidchambers](https://github.com/davidchambers) (David Chambers) My existing contributions and all future contributions until further notice are Copyright David Chambers, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
hierarchy/Main.hs+18−15
@@ -18,13 +18,16 @@
1818
1919module Main where
2020
21+import Control.Applicative (optional)
2122import Control.Monad (unless)
2223
2324import Data.List (intercalate,nub,sort)
2425import Data.Foldable (for_)
2526import Data.Version (showVersion)
27+import Data.Monoid ((<>))
2628
27−import Options.Applicative
29+import Options.Applicative (Parser)
30+import qualified Options.Applicative as Opts
2831import System.Directory (createDirectoryIfMissing)
2932import System.FilePath ((</>))
3033import System.FilePath.Glob (glob)
@@ -90,26 +93,26 @@ superClasses (P.PositionedDeclaration _ _ decl) = superClasses decl
9093superClasses _ = []
9194
9295inputFile :: Parser FilePath
93−inputFile = strArgument $
94− metavar "FILE"
95− <> value "main.purs"
96− <> showDefault
97− <> help "The input file to generate a hierarchy from"
96+inputFile = Opts.strArgument $
97+ Opts.metavar "FILE"
98+ <> Opts.value "main.purs"
99+ <> Opts.showDefault
100+ <> Opts.help "The input file to generate a hierarchy from"
98101
99102outputFile :: Parser (Maybe FilePath)
100−outputFile = optional . strOption $
101− short 'o'
102− <> long "output"
103− <> help "The output directory"
103+outputFile = optional . Opts.strOption $
104+ Opts.short 'o'
105+ <> Opts.long "output"
106+ <> Opts.help "The output directory"
104107
105108pscOptions :: Parser HierarchyOptions
106109pscOptions = HierarchyOptions <$> inputFile
107110 <*> outputFile
108111
109112main :: IO ()
110−main = execParser opts >>= compile
113+main = Opts.execParser opts >>= compile
111114 where
112− opts = info (helper <*> pscOptions) infoModList
113− infoModList = fullDesc <> headerInfo <> footerInfo
114− headerInfo = header "hierarchy - Creates a GraphViz directed graph of PureScript TypeClasses"
115− footerInfo = footer $ "hierarchy " ++ showVersion Paths.version
115+ opts = Opts.info (Opts.helper <*> pscOptions) infoModList
116+ infoModList = Opts.fullDesc <> headerInfo <> footerInfo
117+ headerInfo = Opts.header "hierarchy - Creates a GraphViz directed graph of PureScript TypeClasses"
118+ footerInfo = Opts.footer $ "hierarchy " ++ showVersion Paths.version
psc-bundle/Main.hs+28−25
@@ -8,6 +8,7 @@ module Main (main) where
88
99import Data.Traversable (for)
1010import Data.Version (showVersion)
11+import Data.Monoid ((<>))
1112
1213import Control.Applicative
1314import Control.Monad
@@ -24,7 +25,8 @@ import System.Directory (createDirectoryIfMissing)
2425
2526import Language.PureScript.Bundle
2627
27−import Options.Applicative as Opts
28+import Options.Applicative (Parser, ParseError (..))
29+import qualified Options.Applicative as Opts
2830
2931import qualified Paths_purescript as Paths
3032
@@ -64,41 +66,41 @@ options = Options <$> some inputFile
6466 <*> namespace
6567 where
6668 inputFile :: Parser FilePath
67− inputFile = strArgument $
68− metavar "FILE"
69− <> help "The input .js file(s)"
69+ inputFile = Opts.strArgument $
70+ Opts.metavar "FILE"
71+ <> Opts.help "The input .js file(s)"
7072
7173 outputFile :: Parser FilePath
72− outputFile = strOption $
73− short 'o'
74− <> long "output"
75− <> help "The output .js file"
74+ outputFile = Opts.strOption $
75+ Opts.short 'o'
76+ <> Opts.long "output"
77+ <> Opts.help "The output .js file"
7678
7779 entryPoint :: Parser String
78− entryPoint = strOption $
79− short 'm'
80− <> long "module"
81− <> help "Entry point module name(s). All code which is not a transitive dependency of an entry point module will be removed."
80+ entryPoint = Opts.strOption $
81+ Opts.short 'm'
82+ <> Opts.long "module"
83+ <> Opts.help "Entry point module name(s). All code which is not a transitive dependency of an entry point module will be removed."
8284
8385 mainModule :: Parser String
84− mainModule = strOption $
85− long "main"
86− <> help "Generate code to run the main method in the specified module."
86+ mainModule = Opts.strOption $
87+ Opts.long "main"
88+ <> Opts.help "Generate code to run the main method in the specified module."
8789
8890 namespace :: Parser String
89− namespace = strOption $
90− short 'n'
91− <> long "namespace"
91+ namespace = Opts.strOption $
92+ Opts.short 'n'
93+ <> Opts.long "namespace"
9294 <> Opts.value "PS"
93− <> showDefault
94− <> help "Specify the namespace that PureScript modules will be exported to when running in the browser."
95+ <> Opts.showDefault
96+ <> Opts.help "Specify the namespace that PureScript modules will be exported to when running in the browser."
9597
9698-- | Make it go.
9799main :: IO ()
98100main = do
99101 hSetEncoding stdout utf8
100102 hSetEncoding stderr utf8
101− opts <- execParser (info (version <*> helper <*> options) infoModList)
103+ opts <- Opts.execParser (Opts.info (version <*> Opts.helper <*> options) infoModList)
102104 output <- runExceptT (app opts)
103105 case output of
104106 Left err -> do
@@ -111,9 +113,10 @@ main = do
111113 writeFile outputFile js
112114 Nothing -> putStrLn js
113115 where
114− infoModList = fullDesc <> headerInfo <> footerInfo
115− headerInfo = header "psc-bundle - Bundles compiled PureScript modules for the browser"
116− footerInfo = footer $ "psc-bundle " ++ showVersion Paths.version
116+ infoModList = Opts.fullDesc <> headerInfo <> footerInfo
117+ headerInfo = Opts.header "psc-bundle - Bundles compiled PureScript modules for the browser"
118+ footerInfo = Opts.footer $ "psc-bundle " ++ showVersion Paths.version
117119
118120 version :: Parser (a -> a)
119− version = abortOption (InfoMsg (showVersion Paths.version)) $ long "version" <> help "Show the version number" <> hidden
121+ version = Opts.abortOption (InfoMsg (showVersion Paths.version)) $
122+ Opts.long "version" <> Opts.help "Show the version number" <> Opts.hidden
psc-ide-client/Main.hs+8−5
@@ -8,8 +8,10 @@ import Control.Exception
88import qualified Data.ByteString.Char8 as BS8
99import qualified Data.Text.IO as T
1010import Data.Version (showVersion)
11+import Data.Monoid ((<>))
1112import Network
12−import Options.Applicative
13+import Options.Applicative (ParseError (..))
14+import qualified Options.Applicative as Opts
1315import System.Exit
1416import System.IO
1517
@@ -21,15 +23,16 @@ data Options = Options
2123
2224main :: IO ()
2325main = do
24− Options port <- execParser opts
26+ Options port <- Opts.execParser opts
2527 client port
2628 where
2729 parser =
2830 Options <$>
2931 (PortNumber . fromIntegral <$>
30− option auto (long "port" <> short 'p' <> value (4242 :: Integer)))
31− opts = info (version <*> helper <*> parser) mempty
32− version = abortOption (InfoMsg (showVersion Paths.version)) $ long "version" <> help "Show the version number" <> hidden
32+ Opts.option Opts.auto (Opts.long "port" <> Opts.short 'p' <> Opts.value (4242 :: Integer)))
33+ opts = Opts.info (version <*> Opts.helper <*> parser) mempty
34+ version = Opts.abortOption (InfoMsg (showVersion Paths.version)) $
35+ Opts.long "version" <> Opts.help "Show the version number" <> Opts.hidden
3336
3437client :: PortID -> IO ()
3538client port = do
psc-ide-server/Main.hs+13−12
@@ -38,7 +38,8 @@ import Network hiding (socketPort, accept)
3838import Network.BSD (getProtocolNumber)
3939import Network.Socket hiding (PortNumber, Type,
4040 sClose)
41−import Options.Applicative hiding ((<>))
41+import Options.Applicative (ParseError (..))
42+import qualified Options.Applicative as Opts
4243import System.Directory
4344import System.FilePath
4445import System.IO hiding (putStrLn, print)
@@ -55,7 +56,7 @@ listenOnLocalhost port = do
5556 sClose
5657 (\sock -> do
5758 setSocketOption sock ReuseAddr 1
58− bindSocket sock (SockAddrInet port localhost)
59+ bind sock (SockAddrInet port localhost)
5960 listen sock maxListenQueue
6061 pure sock)
6162
@@ -70,7 +71,7 @@ data Options = Options
7071
7172main :: IO ()
7273main = do
73− Options dir globs outputPath port noWatch debug <- execParser opts
74+ Options dir globs outputPath port noWatch debug <- Opts.execParser opts
7475 maybe (pure ()) setCurrentDirectory dir
7576 ideState <- newTVarIO emptyIdeState
7677 cwd <- getCurrentDirectory
@@ -91,17 +92,17 @@ main = do
9192 where
9293 parser =
9394 Options
94− <$> optional (strOption (long "directory" `mappend` short 'd'))
95− <*> many (argument str (metavar "Source GLOBS..."))
96− <*> strOption (long "output-directory" `mappend` value "output/")
95+ <$> optional (Opts.strOption (Opts.long "directory" `mappend` Opts.short 'd'))
96+ <*> many (Opts.argument Opts.str (Opts.metavar "Source GLOBS..."))
97+ <*> Opts.strOption (Opts.long "output-directory" `mappend` Opts.value "output/")
9798 <*> (fromIntegral <$>
98− option auto (long "port" `mappend` short 'p' `mappend` value (4242 :: Integer)))
99− <*> switch (long "no-watch")
100− <*> switch (long "debug")
101− opts = info (version <*> helper <*> parser) mempty
102− version = abortOption
99+ Opts.option Opts.auto (Opts.long "port" `mappend` Opts.short 'p' `mappend` Opts.value (4242 :: Integer)))
100+ <*> Opts.switch (Opts.long "no-watch")
101+ <*> Opts.switch (Opts.long "debug")
102+ opts = Opts.info (version <*> Opts.helper <*> parser) mempty
103+ version = Opts.abortOption
103104 (InfoMsg (showVersion Paths.version))
104− (long "version" `mappend` help "Show the version number")
105+ (Opts.long "version" `mappend` Opts.help "Show the version number")
105106
106107startServer :: PortNumber -> IdeEnvironment -> IO ()
107108startServer port env = withSocketsDo $ do
psc-publish/Main.hs+13−10
@@ -4,8 +4,10 @@ module Main where
44import Data.Version (Version(..), showVersion)
55import qualified Data.Aeson as A
66import qualified Data.ByteString.Lazy.Char8 as BL
7+import Data.Monoid ((<>))
78
8−import Options.Applicative hiding (str)
9+import Options.Applicative (Parser, ParseError (..))
10+import qualified Options.Applicative as Opts
911
1012import System.IO (hSetEncoding, stderr, stdout, utf8)
1113
@@ -14,9 +16,9 @@ import Language.PureScript.Publish
1416import Language.PureScript.Publish.ErrorsWarnings
1517
1618dryRun :: Parser Bool
17−dryRun = switch $
18− long "dry-run"
19− <> help "Produce no output, and don't require a tagged version to be checked out."
19+dryRun = Opts.switch $
20+ Opts.long "dry-run"
21+ <> Opts.help "Produce no output, and don't require a tagged version to be checked out."
2022
2123dryRunOptions :: PublishOptions
2224dryRunOptions = defaultPublishOptions
@@ -29,15 +31,16 @@ main :: IO ()
2931main = do
3032 hSetEncoding stdout utf8
3133 hSetEncoding stderr utf8
32− execParser opts >>= publish
34+ Opts.execParser opts >>= publish
3335 where
34− opts = info (version <*> helper <*> dryRun) infoModList
35− infoModList = fullDesc <> headerInfo <> footerInfo
36− headerInfo = header "psc-publish - Generates documentation packages for upload to http://pursuit.purescript.org"
37− footerInfo = footer $ "psc-publish " ++ showVersion Paths.version
36+ opts = Opts.info (version <*> Opts.helper <*> dryRun) infoModList
37+ infoModList = Opts.fullDesc <> headerInfo <> footerInfo
38+ headerInfo = Opts.header "psc-publish - Generates documentation packages for upload to http://pursuit.purescript.org"
39+ footerInfo = Opts.footer $ "psc-publish " ++ showVersion Paths.version
3840
3941 version :: Parser (a -> a)
40− version = abortOption (InfoMsg (showVersion Paths.version)) $ long "version" <> help "Show the version number" <> hidden
42+ version = Opts.abortOption (InfoMsg (showVersion Paths.version)) $
43+ Opts.long "version" <> Opts.help "Show the version number" <> Opts.hidden
4144
4245publish :: Bool -> IO ()
4346publish isDryRun =