diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2016-12-12 20:43:42 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2016-12-12 20:43:42 +0300 |
commit | f1a4c2b98f1707c09e17ddd07cb25d6e1cfe4022 (patch) | |
tree | 55877ee2e87e89b552b194966292f6f46eb0982f /apps/RemovePath.hs | |
parent | fix export lists (diff) | |
download | windows-env-f1a4c2b98f1707c09e17ddd07cb25d6e1cfe4022.tar.gz windows-env-f1a4c2b98f1707c09e17ddd07cb25d6e1cfe4022.zip |
use monad transformers
Diffstat (limited to 'apps/RemovePath.hs')
-rw-r--r-- | apps/RemovePath.hs | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/apps/RemovePath.hs b/apps/RemovePath.hs index eb1cb00..02bda10 100644 --- a/apps/RemovePath.hs +++ b/apps/RemovePath.hs @@ -7,6 +7,8 @@ module Main (main) where import Control.Monad (void, when) +import Control.Monad.Trans.Class +import Control.Monad.Trans.Except import Data.List ((\\)) import System.IO.Error (ioError, isDoesNotExistError) @@ -52,9 +54,8 @@ main = execParser parser >>= removePath removePath :: Options -> IO () removePath options = do - removePathFrom Env.CurrentUser - when forAllUsers $ - removePathFrom Env.AllUsers + ret <- runExceptT $ doRemovePath + either ioError return ret where varName = optName options pathsToRemove = optPaths options @@ -63,13 +64,18 @@ removePath options = do skipPrompt = optYes options - removePathFrom profile = do - oldValue <- Env.query profile varName - either ignoreMissing (doRemovePathFrom profile) oldValue - ignoreMissing e - | isDoesNotExistError e = return () - | otherwise = ioError e + | isDoesNotExistError e = return "" + | otherwise = throwE e + + doRemovePath = do + removePathFrom Env.CurrentUser + when forAllUsers $ + removePathFrom Env.AllUsers + + removePathFrom profile = do + oldValue <- Env.query profile varName `catchE` ignoreMissing + doRemovePathFrom profile oldValue doRemovePathFrom profile oldValue = do let oldPaths = Env.pathSplit oldValue @@ -80,4 +86,4 @@ removePath options = do then withoutPrompt else withPrompt $ engraveMessage profile varName oldValue newValue let engrave = Env.engrave profile varName newValue - void $ promptAnd engrave + lift $ void $ promptAnd $ runExceptT engrave |