module HashAddressed.App.HashFunction.Options ( hashFunctionRead, hashFunctionInstructions, ) where import Essentials import HashAddressed.App.HashFunction.Naming import HashAddressed.HashFunction (HashFunction) import Prelude (String) import qualified Control.Monad as Monad import qualified Data.List as List import qualified Options.Applicative as Options hashFunctionRead :: Options.ReadM HashFunction hashFunctionRead :: ReadM HashFunction hashFunctionRead = do String string <- forall s. IsString s => ReadM s Options.str case forall a b. Eq a => a -> [(a, b)] -> Maybe b List.lookup (String -> String normalizeHashFunction String string) [(String, HashFunction)] hashFunctions of Just HashFunction x -> forall (f :: * -> *) a. Applicative f => a -> f a pure HashFunction x Maybe HashFunction Nothing -> forall (m :: * -> *) a. MonadFail m => String -> m a Monad.fail forall a b. (a -> b) -> a -> b $ String "Unsupported hash function. Choices are: " forall a. Semigroup a => a -> a -> a <> String choices choices :: String choices :: String choices = String "[ SHA-256 ]" hashFunctionInstructions :: String hashFunctionInstructions :: String hashFunctionInstructions = String "Choices: " forall a. Semigroup a => a -> a -> a <> String choices forall a. Semigroup a => a -> a -> a <> String "; space, dash, underscore, and letter case are ignored"