{-# LANGUAGE OverloadedStrings #-}

module Network.ZRE.Options (
    parseOptions
  ) where

import Options.Applicative
import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as B

import Network.ZRE.Types
import System.ZMQ4.Endpoint

parseOptions :: Parser ZRECfg
parseOptions :: Parser ZRECfg
parseOptions = ByteString
-> Float
-> Float
-> Float
-> Float
-> [ByteString]
-> Endpoint
-> Maybe Endpoint
-> Bool
-> ZRECfg
ZRECfg
  forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> ByteString
B.pack forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s. IsString s => Mod OptionFields s -> Parser s
strOption
        (forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"name"
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'n'
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasValue f => a -> Mod f a
value String
""
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. String -> Mod f a
help String
"Node name"))
  forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall a. ReadM a -> Mod OptionFields a -> Parser a
option forall a. Read a => ReadM a
auto
        (forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"quiet-period"
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'q'
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"N"
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasValue f => a -> Mod f a
value Float
1.0
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. String -> Mod f a
help String
"Ping peer after N seconds"))
  forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall a. ReadM a -> Mod OptionFields a -> Parser a
option forall a. Read a => ReadM a
auto
        (forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"quiet-ping-rate"
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'p'
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"N"
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasValue f => a -> Mod f a
value Float
1.0
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. String -> Mod f a
help String
"Peer ping rate after quiet period passed"))
  forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall a. ReadM a -> Mod OptionFields a -> Parser a
option forall a. Read a => ReadM a
auto
        (forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"dead-period"
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'd'
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"N"
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasValue f => a -> Mod f a
value Float
5.0
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. String -> Mod f a
help String
"Mark peer dead after N seconds"))
  forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall a. ReadM a -> Mod OptionFields a -> Parser a
option forall a. Read a => ReadM a
auto
         (forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"beacon-period"
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'b'
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"N"
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasValue f => a -> Mod f a
value Float
0.9
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. String -> Mod f a
help String
"Send beacon every N seconds"))
  forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((forall a b. (a -> b) -> [a] -> [b]
map String -> ByteString
B.pack) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (forall s. IsString s => Mod OptionFields s -> Parser s
strOption
        (forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"interface"
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'i'
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"IFACE"
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. String -> Mod f a
help String
"Interfaces")))
  forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. ReadM a -> Mod OptionFields a -> Parser a
option (forall a. (ByteString -> Either String a) -> ReadM a
attoReadM ByteString -> Either String Endpoint
parseAttoUDPEndpoint)
        (forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"multicast-group"
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'm'
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"IP:PORT"
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasValue f => a -> Mod f a
value Endpoint
defMCastEndpoint
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. String -> Mod f a
help String
"IP:PORT of the multicast group")
  forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (forall a. ReadM a -> Mod OptionFields a -> Parser a
option (forall a. (ByteString -> Either String a) -> ReadM a
attoReadM ByteString -> Either String Endpoint
parseAttoTCPEndpoint)
        (forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"gossip"
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'g'
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"IP:PORT"
      forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. String -> Mod f a
help String
"IP:PORT of the gossip server"))
  forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mod FlagFields Bool -> Parser Bool
switch (forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"debug" forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'd')

attoReadM :: (ByteString -> Either String a) -> ReadM a
attoReadM :: forall a. (ByteString -> Either String a) -> ReadM a
attoReadM ByteString -> Either String a
p = forall a. (String -> Either String a) -> ReadM a
eitherReader (ByteString -> Either String a
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
B.pack)