module Blockfrost.Env
( Env (..)
, parseEnv
) where
import Data.Text (Text)
import qualified Data.Text
import GHC.Generics (Generic)
import qualified Text.Read
data Env =
Ipfs
| Mainnet
| Testnet
| Preprod
| Preview
| Sanchonet
| Localhost
deriving (Env -> Env -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Env -> Env -> Bool
$c/= :: Env -> Env -> Bool
== :: Env -> Env -> Bool
$c== :: Env -> Env -> Bool
Eq, ReadPrec [Env]
ReadPrec Env
Int -> ReadS Env
ReadS [Env]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Env]
$creadListPrec :: ReadPrec [Env]
readPrec :: ReadPrec Env
$creadPrec :: ReadPrec Env
readList :: ReadS [Env]
$creadList :: ReadS [Env]
readsPrec :: Int -> ReadS Env
$creadsPrec :: Int -> ReadS Env
Read, Int -> Env -> ShowS
[Env] -> ShowS
Env -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Env] -> ShowS
$cshowList :: [Env] -> ShowS
show :: Env -> String
$cshow :: Env -> String
showsPrec :: Int -> Env -> ShowS
$cshowsPrec :: Int -> Env -> ShowS
Show, Eq Env
Env -> Env -> Bool
Env -> Env -> Ordering
Env -> Env -> Env
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Env -> Env -> Env
$cmin :: Env -> Env -> Env
max :: Env -> Env -> Env
$cmax :: Env -> Env -> Env
>= :: Env -> Env -> Bool
$c>= :: Env -> Env -> Bool
> :: Env -> Env -> Bool
$c> :: Env -> Env -> Bool
<= :: Env -> Env -> Bool
$c<= :: Env -> Env -> Bool
< :: Env -> Env -> Bool
$c< :: Env -> Env -> Bool
compare :: Env -> Env -> Ordering
$ccompare :: Env -> Env -> Ordering
Ord, forall x. Rep Env x -> Env
forall x. Env -> Rep Env x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Env x -> Env
$cfrom :: forall x. Env -> Rep Env x
Generic)
parseEnv :: Text -> Either Text Env
parseEnv :: Text -> Either Text Env
parseEnv Text
tEnv = case forall a. Read a => String -> Maybe a
Text.Read.readMaybe (Text -> String
Data.Text.unpack forall a b. (a -> b) -> a -> b
$ Text -> Text
Data.Text.toTitle Text
tEnv) of
Just Env
env -> forall (f :: * -> *) a. Applicative f => a -> f a
pure Env
env
Maybe Env
Nothing ->
forall a b. a -> Either a b
Left
forall a b. (a -> b) -> a -> b
$ Text
"Unknown environment: `" forall a. Semigroup a => a -> a -> a
<> Text
tEnv forall a. Semigroup a => a -> a -> a
<> Text
"`"
forall a. Semigroup a => a -> a -> a
<> Text
" expecting one of `ipfs`, `mainnet`, `testnet`, `preprod`, `preview`, `sanchonet`, `localhost`"