From 54db9a94963826141c79ffe30df0453f85a117c8 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Wed, 13 Jul 2016 03:28:51 +0300 Subject: bugfix + refactoring --- apps/ListPath.hs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'apps/ListPath.hs') 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 -- cgit v1.2.3