module Rattletrap.Console.Mode where

data Mode
  = Decode
  | Encode
  deriving (Mode -> Mode -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Mode -> Mode -> Bool
$c/= :: Mode -> Mode -> Bool
== :: Mode -> Mode -> Bool
$c== :: Mode -> Mode -> Bool
Eq, Int -> Mode -> ShowS
[Mode] -> ShowS
Mode -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Mode] -> ShowS
$cshowList :: [Mode] -> ShowS
show :: Mode -> String
$cshow :: Mode -> String
showsPrec :: Int -> Mode -> ShowS
$cshowsPrec :: Int -> Mode -> ShowS
Show)

fromString :: String -> Either String Mode
fromString :: String -> Either String Mode
fromString String
string = case String
string of
  String
"decode" -> forall a b. b -> Either a b
Right Mode
Decode
  String
"encode" -> forall a b. b -> Either a b
Right Mode
Encode
  String
_ -> forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ String
"invalid mode: " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show String
string