aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/Environment.hs
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-07-12 00:29:40 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-07-12 00:29:40 +0300
commit7b4f37ffad0098a829f8b1c9cab26d51cd732bbc (patch)
tree4a3eb18e9e73fa570c043dc543e19b78d277c6bd /src/Environment.hs
parentrename modules + fix compiler warnings (diff)
downloadwindows-env-7b4f37ffad0098a829f8b1c9cab26d51cd732bbc.tar.gz
windows-env-7b4f37ffad0098a829f8b1c9cab26d51cd732bbc.zip
code style
Diffstat (limited to '')
-rw-r--r--src/Environment.hs61
1 files changed, 32 insertions, 29 deletions
diff --git a/src/Environment.hs b/src/Environment.hs
index 0690278..2b53258 100644
--- a/src/Environment.hs
+++ b/src/Environment.hs
@@ -4,29 +4,32 @@
- See LICENSE.txt for details.
-}
-module Environment ( saveToRegistry
- , saveToRegistryWithPrompt
- , queryFromRegistry
- , wipeFromRegistry
- , wipeFromRegistryWithPrompt
- , getEnv
- , splitPaths
- , joinPaths
- , RegistryBasedEnvironment(..) ) where
-
-import Control.Monad ( liftM, when )
-import Data.List ( intercalate )
-import Data.List.Split ( splitOn )
-import Data.Maybe ( fromMaybe )
-import qualified System.Environment ( lookupEnv )
-import System.IO.Error ( catchIOError, isDoesNotExistError )
+module Environment
+ ( saveToRegistry
+ , saveToRegistryWithPrompt
+ , queryFromRegistry
+ , wipeFromRegistry
+ , wipeFromRegistryWithPrompt
+ , getEnv
+ , splitPaths
+ , joinPaths
+ , RegistryBasedEnvironment(..)
+ ) where
+
+import Control.Monad (liftM, when)
+import Data.List (intercalate)
+import Data.List.Split (splitOn)
+import Data.Maybe (fromMaybe)
+import qualified System.Environment (lookupEnv)
+import System.IO.Error (catchIOError, isDoesNotExistError)
import qualified Registry
-import qualified Utils ( promptToContinue )
+import qualified Utils (promptToContinue)
-data RegistryBasedEnvironment = CurrentUserEnvironment
- | AllUsersEnvironment
- deriving (Eq, Show)
+data RegistryBasedEnvironment
+ = CurrentUserEnvironment
+ | AllUsersEnvironment
+ deriving (Eq, Show)
registrySubKeyPath :: RegistryBasedEnvironment -> String
registrySubKeyPath CurrentUserEnvironment = "Environment"
@@ -45,12 +48,12 @@ saveToRegistry env = Registry.setString (registryKey env) (registrySubKeyPath en
saveToRegistryWithPrompt :: RegistryBasedEnvironment -> String -> String -> IO ()
saveToRegistryWithPrompt env name value = do
- putStrLn $ "Saving variable '" ++ name ++ "' to '" ++ registryKeyPath env ++ "'..."
- oldValue <- queryFromRegistry env name
- putStrLn $ "\tOld value: " ++ oldValue
- putStrLn $ "\tNew value: " ++ value
- agreed <- Utils.promptToContinue
- when agreed $ saveToRegistry env name value
+ putStrLn $ "Saving variable '" ++ name ++ "' to '" ++ registryKeyPath env ++ "'..."
+ oldValue <- queryFromRegistry env name
+ putStrLn $ "\tOld value: " ++ oldValue
+ putStrLn $ "\tNew value: " ++ value
+ agreed <- Utils.promptToContinue
+ when agreed $ saveToRegistry env name value
queryFromRegistry :: RegistryBasedEnvironment -> String -> IO String
queryFromRegistry env name = catchIOError (Registry.getString (registryKey env) (registrySubKeyPath env) name) emptyIfDoesNotExist
@@ -66,9 +69,9 @@ wipeFromRegistry env name = catchIOError (Registry.delValue (registryKey env) (r
wipeFromRegistryWithPrompt :: RegistryBasedEnvironment -> String -> IO ()
wipeFromRegistryWithPrompt env name = do
- putStrLn $ "Deleting variable '" ++ name ++ "' from '" ++ registryKeyPath env ++ "'..."
- agreed <- Utils.promptToContinue
- when agreed $ wipeFromRegistry env name
+ putStrLn $ "Deleting variable '" ++ name ++ "' from '" ++ registryKeyPath env ++ "'..."
+ agreed <- Utils.promptToContinue
+ when agreed $ wipeFromRegistry env name
getEnv :: String -> IO String
getEnv = liftM (fromMaybe "") . System.Environment.lookupEnv