Update 'fenv.hs'

This commit is contained in:
Garrett Mills 2021-09-30 18:44:56 +00:00
parent 4df7458362
commit b71439326e

14
fenv.hs
View File

@ -11,10 +11,24 @@ data EnvFile =
| Entry EnvKey EnvValue EnvFile | Entry EnvKey EnvValue EnvFile
deriving (Show,Eq,Read) deriving (Show,Eq,Read)
dispatch :: [(String, [String] -> IO ())]
dispatch = [
("get", cliGet),
("set", cliSet),
("unset", cliUnset)
]
main = do main = do
let f = (Entry "foo" "bar" End) let f = (Entry "foo" "bar" End)
putStrLn (show f) 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 :: EnvFile -> EnvKey -> EnvValue -> EnvFile
setEntry env key value = let env'=(removeEntry env key) in setEntry env key value = let env'=(removeEntry env key) in
(Entry key value env') (Entry key value env')