cabal-gild-0.3.0.1: source/library/CabalGild/Type/Mode.hs
module CabalGild.Type.Mode where
import qualified CabalGild.Exception.InvalidMode as InvalidMode
import qualified Control.Monad.Catch as Exception
-- | Represents the mode of the command line utility.
data Mode
= -- | Just determine if the input is already formatted.
Check
| -- | Format the input.
Format
deriving (Eq, Show)
-- | Attempts to parse a string as a mode.
fromString :: (Exception.MonadThrow m) => String -> m Mode
fromString s = case s of
"check" -> pure Check
"format" -> pure Format
_ -> Exception.throwM $ InvalidMode.fromString s