aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-01-16 05:08:00 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2017-01-16 05:08:00 +0300
commiteb64b221eb101c51c815f57fae6cf29502ca987b (patch)
tree2f5625a1ad3f49769c7fe187150ebfa01f24cb0a
parentrename source files (diff)
downloadwindows-env-eb64b221eb101c51c815f57fae6cf29502ca987b.tar.gz
windows-env-eb64b221eb101c51c815f57fae6cf29502ca987b.zip
code style
-rw-r--r--apps/AddPath.hs5
-rw-r--r--apps/ListPaths.hs17
-rw-r--r--src/Windows/Registry.hs17
3 files changed, 20 insertions, 19 deletions
diff --git a/apps/AddPath.hs b/apps/AddPath.hs
index 7e5ae65..571012d 100644
--- a/apps/AddPath.hs
+++ b/apps/AddPath.hs
@@ -65,8 +65,9 @@ addPath options = runExceptT doAddPath >>= either ioError return
skipPrompt = optYes options
- emptyIfMissing e | isDoesNotExistError e = return ""
- | otherwise = throwE e
+ emptyIfMissing e
+ | isDoesNotExistError e = return ""
+ | otherwise = throwE e
doAddPath = do
oldValue <- Env.query profile varName `catchE` emptyIfMissing
diff --git a/apps/ListPaths.hs b/apps/ListPaths.hs
index 65d374b..dee24d3 100644
--- a/apps/ListPaths.hs
+++ b/apps/ListPaths.hs
@@ -57,13 +57,13 @@ optionParser = Options
<> help "List global (all users') paths only")
main :: IO ()
-main = execParser parser >>= listPath
+main = execParser parser >>= listPaths
where
parser = info (helper <*> optionParser) $
fullDesc <> progDesc "List directories in your PATH"
-listPath :: Options -> IO ()
-listPath options = runExceptT doListPath >>= either ioError return
+listPaths :: Options -> IO ()
+listPaths options = runExceptT doListPaths >>= either ioError return
where
varName = optName options
whichPaths = optWhichPaths options
@@ -74,9 +74,10 @@ listPath options = runExceptT doListPath >>= either ioError return
queryFrom Environment = lift $ fromMaybe "" <$> lookupEnv varName
queryFrom (Registry profile) = Env.query profile varName
- doListPath = do
- paths <- query
- lift $ printPaths $ Env.pathSplit paths
+ filterPaths = filterM $ shouldListPath whichPaths
- printPaths paths =
- filterM (shouldListPath whichPaths) paths >>= mapM_ putStrLn
+ doListPaths = do
+ paths <- Env.pathSplit <$> query
+ lift $ do
+ pathsToPrint <- filterPaths paths
+ mapM_ putStrLn pathsToPrint
diff --git a/src/Windows/Registry.hs b/src/Windows/Registry.hs
index 82abe9c..79d4fb5 100644
--- a/src/Windows/Registry.hs
+++ b/src/Windows/Registry.hs
@@ -136,7 +136,7 @@ decodeString (_, bytes) = T.unpack dropLastZero
| otherwise = T.takeWhile (/= '\0') text
openCloseCatch :: IsKeyPath a => a -> (Handle -> IO b) -> ExceptT IOError IO b
-openCloseCatch keyPath f = ExceptT $ catchIOError (openApplyClose >>= return . Right) $ return . Left
+openCloseCatch keyPath f = ExceptT $ catchIOError (fmap Right openApplyClose) (return . Left)
where
openApplyClose = bracket (openUnsafe keyPath) close f
@@ -175,8 +175,7 @@ queryType keyPath valueName =
alloca $ \valueTypePtr -> do
WinAPI.failUnlessSuccess "RegQueryValueExW" $
c_RegQueryValueEx keyHandlePtr valueNamePtr WinAPI.nullPtr valueTypePtr WinAPI.nullPtr WinAPI.nullPtr
- valueType <- toEnum . fromIntegral <$> peek valueTypePtr
- return valueType
+ toEnum . fromIntegral <$> peek valueTypePtr
data GetValueFlag = RestrictAny
| RestrictNone
@@ -225,7 +224,7 @@ getValue keyPath valueName flags =
valueType <- toEnum . fromIntegral <$> peek valueTypePtr
return (valueType, buffer)
where
- rawFlags = fromIntegral $ foldr (.|.) 0 $ map fromEnum flags
+ rawFlags = fromIntegral $ foldr ((.|.) . fromEnum) 0 flags
getType :: IsKeyPath a => a -> ValueName -> [GetValueFlag] -> ExceptT IOError IO ValueType
getType keyPath valueName flags =
@@ -235,10 +234,9 @@ getType keyPath valueName flags =
alloca $ \valueTypePtr -> do
WinAPI.failUnlessSuccess "RegGetValueW" $
c_RegGetValue keyHandlePtr WinAPI.nullPtr valueNamePtr rawFlags valueTypePtr WinAPI.nullPtr WinAPI.nullPtr
- valueType <- toEnum . fromIntegral <$> peek valueTypePtr
- return valueType
+ toEnum . fromIntegral <$> peek valueTypePtr
where
- rawFlags = fromIntegral $ foldr (.|.) 0 $ map fromEnum $ DoNotExpand : flags
+ rawFlags = fromIntegral $ foldr ((.|.) . fromEnum) 0 (DoNotExpand : flags)
getExpandedString :: IsKeyPath a => a -> ValueName -> ExceptT IOError IO String
getExpandedString keyPath valueName = do
@@ -272,8 +270,9 @@ setStringPreserveType keyPath valueName valueData = do
valueType <- getType keyPath valueName [RestrictString, RestrictExpandableString] `catchE` stringByDefault
setValue keyPath valueName (valueType, encodeString valueData)
where
- stringByDefault e | isDoesNotExistError e = return TypeString
- | otherwise = throwE e
+ stringByDefault e
+ | isDoesNotExistError e = return TypeString
+ | otherwise = throwE e
deleteValue :: IsKeyPath a => a -> ValueName -> ExceptT IOError IO ()
deleteValue keyPath valueName =