aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/apps/ListPath.hs
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-07-13 03:28:51 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-07-13 03:28:51 +0300
commit54db9a94963826141c79ffe30df0453f85a117c8 (patch)
tree22190418728ed381c1c0c45c2d58c5acfda06423 /apps/ListPath.hs
parentreorder imports (diff)
downloadwindows-env-54db9a94963826141c79ffe30df0453f85a117c8.tar.gz
windows-env-54db9a94963826141c79ffe30df0453f85a117c8.zip
bugfix + refactoring
Diffstat (limited to '')
-rw-r--r--apps/ListPath.hs16
1 files changed, 8 insertions, 8 deletions
diff --git a/apps/ListPath.hs b/apps/ListPath.hs
index 63460b9..469fbba 100644
--- a/apps/ListPath.hs
+++ b/apps/ListPath.hs
@@ -16,13 +16,13 @@ import Options.Applicative
import qualified Environment
data Options = Options
- { name :: String
+ { optName :: String
} deriving (Eq, Show)
options :: Parser Options
-options = Options <$> nameOption
+options = Options <$> optNameDesc
where
- nameOption = strOption $
+ optNameDesc = strOption $
long "name" <> short 'n' <> metavar "NAME" <> value "PATH" <>
help "Specify variable name ('PATH' by default)"
@@ -32,14 +32,14 @@ main = execParser parser >>= listPath
parser = info (helper <*> options) $
fullDesc <> progDesc "List directories in your PATH"
-getEnv :: String -> IO String
-getEnv = liftM (fromMaybe "") . lookupEnv
-
listPath :: Options -> IO ()
listPath options = do
- val <- getEnv $ name options
- mapM_ printPath $ Environment.pathSplit val
+ oldValue <- getEnv varName
+ let oldPaths = Environment.pathSplit oldValue
+ mapM_ printPath oldPaths
where
+ varName = optName options
+ getEnv = liftM (fromMaybe "") . lookupEnv
printPath p = do
exists <- doesDirectoryExist p
putStrLn $ (if exists then "+" else "-") ++ " " ++ p