blob: bf5c170f035175b3e0238090f15a0efbd791ab82 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
module Main where
import Fig.Prelude
import Options.Applicative
import qualified Fig.Bus.SExp as SExp
import qualified Fig.Bus.Binary as Binary
data Command = SExp | Binary
parseCommand :: Parser Command
parseCommand = subparser $ mconcat
[ command "sexp" $ info (pure SExp) (progDesc "Launch the s-expression bus")
, command "binary" $ info (pure Binary) (progDesc "Launch the binary bus")
]
data Opts = Opts
{ host :: !Text
, port :: !Text
, cmd :: !Command
}
parseOpts :: Parser Opts
parseOpts = Opts
<$> strOption (long "host" <> metavar "HOST" <> help "Interface to bind" <> value "localhost")
<*> strOption (long "port" <> metavar "PORT" <> help "Port to bind" <> showDefault <> value "32050")
<*> parseCommand
main :: IO ()
main = do
opts <- execParser $ info (parseOpts <**> helper)
( fullDesc
<> header "fig-bus - a pub/sub message bus"
)
case opts.cmd of
SExp -> SExp.main (Just opts.host, opts.port)
Binary -> Binary.main (Just opts.host, opts.port)
|