diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2017-06-11 05:37:27 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2017-06-11 05:37:27 +0300 |
commit | 742c541568f05d160784ace2024ee7256e3bd189 (patch) | |
tree | 1825605080aecab732ac59245dc762f4248945c7 /app | |
parent | windows-env.cabal: fix formatting (diff) | |
download | windows-env-742c541568f05d160784ace2024ee7256e3bd189.tar.gz windows-env-742c541568f05d160784ace2024ee7256e3bd189.zip |
refactoring
Diffstat (limited to '')
-rw-r--r-- | app/AddPath.hs | 2 | ||||
-rw-r--r-- | app/ListPaths.hs | 20 | ||||
-rw-r--r-- | app/RemovePath.hs | 2 | ||||
-rw-r--r-- | app/SetEnv.hs | 4 | ||||
-rw-r--r-- | app/Utils/PromptMessage.hs | 16 |
5 files changed, 21 insertions, 23 deletions
diff --git a/app/AddPath.hs b/app/AddPath.hs index 1993b4a..ff80b18 100644 --- a/app/AddPath.hs +++ b/app/AddPath.hs @@ -97,6 +97,6 @@ addPath options = runExceptT doAddPath >>= either ioError return promptAndEngrave oldValue newValue = do let promptAnd = if skipPrompt then withoutPrompt - else withPrompt $ oldNewMessage profile varName (show oldValue) (show newValue) + else withPrompt $ oldNewMessage profile varName oldValue newValue let engrave = WindowsEnv.engrave profile varName newValue void $ promptAnd engrave diff --git a/app/ListPaths.hs b/app/ListPaths.hs index 8a31cb8..f832686 100644 --- a/app/ListPaths.hs +++ b/app/ListPaths.hs @@ -11,7 +11,6 @@ import Control.Monad (filterM) import Control.Monad.Trans.Class (lift) import Control.Monad.Trans.Except (runExceptT) import Data.Maybe (fromMaybe) -import System.Directory (doesDirectoryExist) import System.Environment (lookupEnv) import System.IO.Error (ioError) @@ -22,10 +21,10 @@ import qualified WindowsEnv data WhichPaths = All | ExistingOnly | MissingOnly deriving (Eq, Show) -shouldListPath :: WhichPaths -> String -> IO Bool +shouldListPath :: WhichPaths -> WindowsEnv.ExpandedPath -> IO Bool shouldListPath All = return . const True -shouldListPath ExistingOnly = doesDirectoryExist -shouldListPath MissingOnly = fmap not . doesDirectoryExist +shouldListPath ExistingOnly = WindowsEnv.pathExists +shouldListPath MissingOnly = fmap not . WindowsEnv.pathExists data Source = Environment | Registry WindowsEnv.Profile deriving (Eq, Show) @@ -71,13 +70,12 @@ listPaths options = runExceptT doListPaths >>= either ioError return query = queryFrom $ optSource options - queryFrom Environment = lift $ fromMaybe "" <$> lookupEnv varName - queryFrom (Registry profile) = show <$> WindowsEnv.query profile varName - - filterPaths = filterM (shouldListPath whichPaths . WindowsEnv.pathExpanded) + queryFrom Environment = lift $ WindowsEnv.VarValue False <$> fromMaybe "" <$> lookupEnv varName + queryFrom (Registry profile) = WindowsEnv.query profile varName doListPaths = do - paths <- query >>= WindowsEnv.pathSplitAndExpand + value <- query + split <- WindowsEnv.pathSplitAndExpand value lift $ do - pathsToPrint <- filterPaths paths - mapM_ (putStrLn . WindowsEnv.pathOriginal) pathsToPrint + wanted <- filterM (shouldListPath whichPaths) split + mapM_ (putStrLn . WindowsEnv.pathOriginal) wanted diff --git a/app/RemovePath.hs b/app/RemovePath.hs index 2d0d47c..23cabb7 100644 --- a/app/RemovePath.hs +++ b/app/RemovePath.hs @@ -85,6 +85,6 @@ removePath options = runExceptT doRemovePath >>= either ioError return let newValue = WindowsEnv.VarValue (WindowsEnv.varValueExpandable oldValue) (WindowsEnv.pathJoin newPaths) let promptAnd = if skipPrompt then withoutPrompt - else withPrompt $ oldNewMessage profile varName (show oldValue) (show newValue) + else withPrompt $ oldNewMessage profile varName oldValue newValue let engrave = WindowsEnv.engrave profile varName newValue void $ promptAnd engrave diff --git a/app/SetEnv.hs b/app/SetEnv.hs index bb058d8..a986226 100644 --- a/app/SetEnv.hs +++ b/app/SetEnv.hs @@ -55,7 +55,7 @@ setEnv :: Options -> IO () setEnv options = runExceptT doSetEnv >>= either ioError return where varName = optName options - varValue = optValue options + varValue = WindowsEnv.VarValue False $ optValue options forAllUsers = optGlobal options profile @@ -67,6 +67,6 @@ setEnv options = runExceptT doSetEnv >>= either ioError return | skipPrompt = withoutPrompt | otherwise = withPrompt $ newMessage profile varName varValue - engrave = WindowsEnv.engrave profile varName $ WindowsEnv.VarValue False varValue + engrave = WindowsEnv.engrave profile varName varValue doSetEnv = void $ promptAnd engrave diff --git a/app/Utils/PromptMessage.hs b/app/Utils/PromptMessage.hs index 9afffb1..1315b85 100644 --- a/app/Utils/PromptMessage.hs +++ b/app/Utils/PromptMessage.hs @@ -15,25 +15,25 @@ import Text.Printf (printf) import qualified WindowsEnv -oldNewMessage :: WindowsEnv.Profile -> WindowsEnv.VarName -> String -> String -> String +oldNewMessage :: WindowsEnv.Profile -> WindowsEnv.VarName -> WindowsEnv.VarValue -> WindowsEnv.VarValue -> String oldNewMessage profile name oldValue newValue = descrMsg ++ oldValueMsg ++ newValueMsg where profileKey = WindowsEnv.profileKeyPath profile - descrMsg = printf "Saving variable '%s' to '%s'...\n" name (show profileKey) - oldValueMsg = printf "\tOld value: %s\n" oldValue - newValueMsg = printf "\tNew value: %s\n" newValue + descrMsg = printf "Saving variable '%s' to '%s'...\n" name $ show profileKey + oldValueMsg = printf "\tOld value: %s\n" $ WindowsEnv.varValueString oldValue + newValueMsg = printf "\tNew value: %s\n" $ WindowsEnv.varValueString newValue -newMessage :: WindowsEnv.Profile -> WindowsEnv.VarName -> String -> String +newMessage :: WindowsEnv.Profile -> WindowsEnv.VarName -> WindowsEnv.VarValue -> String newMessage profile name newValue = descrMsg ++ newValueMsg where profileKey = WindowsEnv.profileKeyPath profile - descrMsg = printf "Saving variable '%s' to '%s'...\n" name (show profileKey) - newValueMsg = printf "\tNew value: %s\n" newValue + descrMsg = printf "Saving variable '%s' to '%s'...\n" name $ show profileKey + newValueMsg = printf "\tNew value: %s\n" $ WindowsEnv.varValueString newValue wipeMessage :: WindowsEnv.Profile -> WindowsEnv.VarName -> String wipeMessage profile name = - printf "Deleting variable '%s' from '%s'...\n" name (show profileKey) + printf "Deleting variable '%s' from '%s'...\n" name $ show profileKey where profileKey = WindowsEnv.profileKeyPath profile |