From b71439326eb254fefd2216d0c028afb611b93278 Mon Sep 17 00:00:00 2001 From: Garrett Mills Date: Thu, 30 Sep 2021 18:44:56 +0000 Subject: [PATCH] Update 'fenv.hs' --- fenv.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/fenv.hs b/fenv.hs index d0413fb..6cdef91 100644 --- a/fenv.hs +++ b/fenv.hs @@ -11,10 +11,24 @@ data EnvFile = | Entry EnvKey EnvValue EnvFile deriving (Show,Eq,Read) +dispatch :: [(String, [String] -> IO ())] +dispatch = [ + ("get", cliGet), + ("set", cliSet), + ("unset", cliUnset) + ] + main = do let f = (Entry "foo" "bar" End) putStrLn (show f) +cliGet :: [String] -> IO () +cliGet (name:_) = do + env <- getEnvFile + case (getEntry env name) of + (Just value) -> putStrLn value + Nothing -> putStrLn "ERROR: No value defined" + setEntry :: EnvFile -> EnvKey -> EnvValue -> EnvFile setEntry env key value = let env'=(removeEntry env key) in (Entry key value env')