{-| Module : Werewolf.Command.Circle Description : Options and handler for the circle subcommand. Copyright : (c) Henry J. Wylde, 2016 License : BSD3 Maintainer : public@hjwylde.com Options and handler for the circle subcommand. -} module Werewolf.Command.Circle ( -- * Options Options(..), -- * Handle handle, ) where import Control.Monad.Except import Control.Monad.Extra import Control.Monad.State import Control.Monad.Writer import Data.Text (Text) import Game.Werewolf import Werewolf.Game import Werewolf.Messages data Options = Options { optIncludeDead :: Bool } deriving (Eq, Show) handle :: MonadIO m => Text -> Options -> m () handle callerName (Options includeDead) = do unlessM doesGameExist $ exitWith failure { messages = [noGameRunningMessage callerName] } game <- readGame let command = circleCommand callerName includeDead case runExcept (execWriterT $ execStateT (apply command) game) of Left errorMessages -> exitWith failure { messages = errorMessages } Right messages -> exitWith success { messages = messages }