feat: add notify command and cli args
This commit is contained in:
parent
92a97e8f8a
commit
fd18fa1a8b
10 changed files with 141 additions and 24 deletions
|
@ -1,6 +1,6 @@
|
|||
{-# LANGUAGE DerivingVia #-}
|
||||
|
||||
module Types.AppTypes (Env (..), App (..), getConnectedClientState, AppProfile (Prod, Dev)) where
|
||||
module Types.AppTypes (Env (..), App (..), HasConfig (getConfig), getConnectedClientState, AppProfile (Prod, Dev)) where
|
||||
|
||||
import ClassyPrelude
|
||||
import State.ConnectedClientsState
|
||||
|
@ -8,13 +8,15 @@ import State.RoomsState
|
|||
( HasRoomsState (getRoomsState),
|
||||
RoomsState,
|
||||
)
|
||||
import Types.Config (ServerOptions)
|
||||
|
||||
data AppProfile = Prod | Dev
|
||||
|
||||
data Env = Env
|
||||
{ connectedClientsState :: ConnectedClientsState,
|
||||
roomsState :: RoomsState,
|
||||
profile :: AppProfile
|
||||
profile :: AppProfile,
|
||||
config :: ServerOptions
|
||||
}
|
||||
|
||||
instance HasConnectedClientState Env where
|
||||
|
@ -23,6 +25,12 @@ instance HasConnectedClientState Env where
|
|||
instance HasRoomsState Env where
|
||||
getRoomsState = roomsState
|
||||
|
||||
class HasConfig a where
|
||||
getConfig :: a -> ServerOptions
|
||||
|
||||
instance HasConfig Env where
|
||||
getConfig = config
|
||||
|
||||
newtype App env a = App {unApp :: env -> IO a}
|
||||
deriving
|
||||
( Functor,
|
||||
|
|
61
backend/src/Types/Config.hs
Normal file
61
backend/src/Types/Config.hs
Normal file
|
@ -0,0 +1,61 @@
|
|||
module Types.Config
|
||||
( ServerOptions (..),
|
||||
serverOptionsParser,
|
||||
)
|
||||
where
|
||||
|
||||
import ClassyPrelude
|
||||
( Applicative ((<*>)),
|
||||
Int,
|
||||
Semigroup ((<>)),
|
||||
Show,
|
||||
String,
|
||||
(<$>),
|
||||
)
|
||||
import Options.Applicative (Parser, auto, help, long, metavar, option, short, showDefault, strOption, value)
|
||||
|
||||
data ServerOptions = ServerOptions
|
||||
{ port :: Int, -- Main server port
|
||||
websocketPort :: Int, -- WebSocket server port
|
||||
listenAddress :: String, -- Address to bind the server
|
||||
notifyExecutable :: String -- Path to the notify executable
|
||||
}
|
||||
deriving (Show)
|
||||
|
||||
serverOptionsParser :: Parser ServerOptions
|
||||
serverOptionsParser =
|
||||
ServerOptions
|
||||
<$> option
|
||||
auto
|
||||
( long "port"
|
||||
<> short 'p'
|
||||
<> metavar "PORT"
|
||||
<> help "Port number for the main server (default: 8081)"
|
||||
<> value 8081
|
||||
<> showDefault
|
||||
)
|
||||
<*> option
|
||||
auto
|
||||
( long "websocketPort"
|
||||
<> short 'w'
|
||||
<> metavar "WS_PORT"
|
||||
<> help "Port number for the WebSocket server (default: 9160)"
|
||||
<> value 9160
|
||||
<> showDefault
|
||||
)
|
||||
<*> strOption
|
||||
( long "listenAddress"
|
||||
<> short 'l'
|
||||
<> metavar "ADDRESS"
|
||||
<> help "IP address or hostname to bind the server (default: 127.0.0.1)"
|
||||
<> value "127.0.0.1"
|
||||
<> showDefault
|
||||
)
|
||||
<*> strOption
|
||||
( long "notifyExecutable"
|
||||
<> short 'n'
|
||||
<> metavar "EXECUTABLE"
|
||||
<> help "Path to the notify executable (default: /usr/bin/notify)"
|
||||
<> value "/usr/bin/notify"
|
||||
<> showDefault
|
||||
)
|
|
@ -10,6 +10,7 @@ import State.ConnectedClientsState (HasConnectedClientState (getConnectedClientS
|
|||
import State.RoomsState (HasRoomsState (getRoomsState))
|
||||
import Types.AppTypes
|
||||
( Env (..),
|
||||
HasConfig (getConfig),
|
||||
)
|
||||
|
||||
class HasWebEnv a where
|
||||
|
@ -31,3 +32,6 @@ instance HasRoomsState WebEnv where
|
|||
instance HasWebEnv WebEnv where
|
||||
getRequest = request
|
||||
getRespond = respond
|
||||
|
||||
instance HasConfig WebEnv where
|
||||
getConfig = getConfig . appEnv
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue