aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/app
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-06-10 16:43:28 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2017-06-10 16:43:28 +0300
commit7de4187052b98ea837d9634eea4a0fcbc6435228 (patch)
treed2b9d102ccfd7d8645846e7c7156003e1d3be8a9 /app
parentdelpath: remove all directory path occurrences (diff)
downloadwindows-env-7de4187052b98ea837d9634eea4a0fcbc6435228.tar.gz
windows-env-7de4187052b98ea837d9634eea4a0fcbc6435228.zip
refactoring
Diffstat (limited to '')
-rw-r--r--app/ListPaths.hs25
1 files changed, 4 insertions, 21 deletions
diff --git a/app/ListPaths.hs b/app/ListPaths.hs
index 5834f11..4193ad6 100644
--- a/app/ListPaths.hs
+++ b/app/ListPaths.hs
@@ -9,7 +9,7 @@ module Main (main) where
import Control.Monad (filterM)
import Control.Monad.Trans.Class (lift)
-import Control.Monad.Trans.Except (ExceptT, runExceptT)
+import Control.Monad.Trans.Except (runExceptT)
import Data.Maybe (fromMaybe)
import System.Directory (doesDirectoryExist)
import System.Environment (lookupEnv)
@@ -63,23 +63,6 @@ main = execParser parser >>= listPaths
parser = info (helper <*> optionParser) $
fullDesc <> progDesc "List directories in your PATH"
-data ExpandedPath = ExpandedPath
- { pathOriginal :: WindowsEnv.VarValue
- , pathExpanded :: WindowsEnv.VarValue
- } deriving (Eq, Show)
-
-splitAndExpand :: WindowsEnv.VarValue -> ExceptT IOError IO [ExpandedPath]
-splitAndExpand pathValue = do
- expandedOnce <- expandOnce
- zipWith ExpandedPath originalPaths <$>
- if length expandedOnce == length originalPaths
- then return expandedOnce
- else expandEach
- where
- originalPaths = WindowsEnv.pathSplit pathValue
- expandOnce = WindowsEnv.pathSplit <$> WindowsEnv.expand pathValue
- expandEach = mapM WindowsEnv.expand originalPaths
-
listPaths :: Options -> IO ()
listPaths options = runExceptT doListPaths >>= either ioError return
where
@@ -91,10 +74,10 @@ listPaths options = runExceptT doListPaths >>= either ioError return
queryFrom Environment = lift $ fromMaybe "" <$> lookupEnv varName
queryFrom (Registry profile) = WindowsEnv.query profile varName
- filterPaths = filterM (shouldListPath whichPaths . pathExpanded)
+ filterPaths = filterM (shouldListPath whichPaths . WindowsEnv.pathExpanded)
doListPaths = do
- paths <- query >>= splitAndExpand
+ paths <- query >>= WindowsEnv.pathSplitAndExpand
lift $ do
pathsToPrint <- filterPaths paths
- mapM_ (putStrLn . pathOriginal) pathsToPrint
+ mapM_ (putStrLn . WindowsEnv.pathOriginal) pathsToPrint