SFTtech / openage-masterserver

Lobby and matchmaking server for openage in Haskell
https://openage.dev
Other
52 stars 12 forks source link

Add command line Arguments #5

Open tobhe opened 8 years ago

tobhe commented 8 years ago

Reader Monad

To be able to overwrite config settings with command line arguments i had to rethink the way we access the config file. In the new solution i removed the now unnecessary getter functions like getPort :: IO Int and instead made the Config globally accessible by using the monad transformer ReaderT and keeping the config in the Reader Monad. Therefore all functions needing config acces now have a type signature of:

(MonadReader Config m, MonadIO m) => a -> m (a)

The config itself can now be loaded with Readers ask function. Single config records can be accessed via asks as in myVersion <- asks acceptedVersion

Command line arguments

Command line arguments are parsed in a new File calles Args.hs. it provides a function named parseOpts which if successful returns a Config object as loaded from the config file, where specially specified records like port are overwritten with the command line arguments. Usage info can be printed with -h or --help and looks like this:

Usage: openage-masterserver [options]...
Options:

  -h       --help         Print help
  -c FILE  --config=FILE  config file to use
  -p NUM   --port=NUM     port to use