diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2016-07-18 04:47:21 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2016-07-18 04:47:21 +0300 |
commit | 62f1e6b804a940506eff5f3f924d2d000e16119d (patch) | |
tree | 443872b2e8ba439cb77de95391bba9319449de08 /apps/ListPath.hs | |
parent | README update (diff) | |
download | windows-env-62f1e6b804a940506eff5f3f924d2d000e16119d.tar.gz windows-env-62f1e6b804a940506eff5f3f924d2d000e16119d.zip |
fix compiler warnings + refactoring
Diffstat (limited to 'apps/ListPath.hs')
-rw-r--r-- | apps/ListPath.hs | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/apps/ListPath.hs b/apps/ListPath.hs index f33983d..03c0e68 100644 --- a/apps/ListPath.hs +++ b/apps/ListPath.hs @@ -18,8 +18,8 @@ data Options = Options { optName :: Env.VarName } deriving (Eq, Show) -options :: Parser Options -options = Options <$> optNameDesc +optionParser :: Parser Options +optionParser = Options <$> optNameDesc where optNameDesc = strOption $ long "name" <> short 'n' <> metavar "NAME" <> value "PATH" <> @@ -28,18 +28,20 @@ options = Options <$> optNameDesc main :: IO () main = execParser parser >>= listPath where - parser = info (helper <*> options) $ + parser = info (helper <*> optionParser) $ fullDesc <> progDesc "List directories in your PATH" listPath :: Options -> IO () listPath options = do - oldValue <- getEnv varName - let oldPaths = Env.pathSplit oldValue - mapM_ printPath oldPaths + oldValue <- query + printPaths $ Env.pathSplit oldValue where varName = optName options - getEnv = liftM (fromMaybe "") . lookupEnv - printPath p = do - exists <- doesDirectoryExist p - putStrLn $ (if exists then "+" else "-") ++ " " ++ p + query = liftM (fromMaybe "") $ lookupEnv varName + + printPath path = do + exists <- doesDirectoryExist path + putStrLn $ (if exists then "+" else "-") ++ " " ++ path + + printPaths = mapM_ printPath |