module HashAddressed.App.HashFunction.Options ( hashFunctionRead, hashFunctionInstructions, ) where import Essentials import HashAddressed.App.HashFunction.Naming import Prelude (String) import qualified Control.Monad as Monad import qualified Data.List as List import qualified Options.Applicative as Options hashFunctionRead :: Options.ReadM HashFunctionName hashFunctionRead :: ReadM HashFunctionName 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, HashFunctionName)] hashFunctions of Just HashFunctionName x -> forall (f :: * -> *) a. Applicative f => a -> f a pure HashFunctionName x Maybe HashFunctionName 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"