aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/apps
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-07-18 00:17:44 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-07-18 00:17:44 +0300
commit427ae9ad54492954578cafbfcd2d815a084e0986 (patch)
treee81cdbf3b9f4d06c921f81a08264b214381d3c8a /apps
parentrefactoring (diff)
downloadwindows-env-427ae9ad54492954578cafbfcd2d815a084e0986.tar.gz
windows-env-427ae9ad54492954578cafbfcd2d815a084e0986.zip
put modules to 'Windows'
Diffstat (limited to 'apps')
-rw-r--r--apps/AddPath.hs21
-rw-r--r--apps/FixNtSymbolPath.hs17
-rw-r--r--apps/ListPath.hs9
-rw-r--r--apps/RemovePath.hs21
-rw-r--r--apps/SetEnv.hs15
-rw-r--r--apps/UnsetEnv.hs13
-rw-r--r--apps/Utils.hs2
7 files changed, 46 insertions, 52 deletions
diff --git a/apps/AddPath.hs b/apps/AddPath.hs
index 6103d1d..db0dcc2 100644
--- a/apps/AddPath.hs
+++ b/apps/AddPath.hs
@@ -11,17 +11,16 @@ import Data.List (union)
import Data.Maybe (fromMaybe)
import Text.Printf (printf)
-import Options.Applicative
-
-import qualified Environment
+import Options.Applicative
+import qualified Windows.Environment as Env
import qualified Utils
data Options = Options
- { optName :: Environment.VarName
+ { optName :: Env.VarName
, optYes :: Bool
, optGlobal :: Bool
- , optPaths :: [Environment.VarValue]
+ , optPaths :: [Env.VarValue]
} deriving (Eq, Show)
options :: Parser Options
@@ -52,21 +51,21 @@ main = execParser parser >>= addPath
addPath :: Options -> IO ()
addPath options = do
- oldValue <- Environment.query profile varName
- let oldPaths = Environment.pathSplit $ fromMaybe "" oldValue
+ oldValue <- Env.query profile varName
+ let oldPaths = Env.pathSplit $ fromMaybe "" oldValue
let newPaths = union oldPaths pathsToAdd
when (length oldPaths /= length newPaths) $ do
- let newValue = Environment.pathJoin newPaths
+ let newValue = Env.pathJoin newPaths
let promptBanner = Utils.engraveBanner profile varName oldValue newValue
- void $ prompt promptBanner $ Environment.engrave profile varName newValue
+ void $ prompt promptBanner $ Env.engrave profile varName newValue
where
varName = optName options
pathsToAdd = optPaths options
forAllUsers = optGlobal options
profile = if forAllUsers
- then Environment.AllUsers
- else Environment.CurrentUser
+ then Env.AllUsers
+ else Env.CurrentUser
skipPrompt = optYes options
prompt = if skipPrompt
diff --git a/apps/FixNtSymbolPath.hs b/apps/FixNtSymbolPath.hs
index 3788381..8c999a8 100644
--- a/apps/FixNtSymbolPath.hs
+++ b/apps/FixNtSymbolPath.hs
@@ -12,9 +12,8 @@ import Data.Maybe (fromMaybe)
import System.Directory (createDirectoryIfMissing, getCurrentDirectory)
import System.FilePath (combine)
-import Options.Applicative
-
-import qualified Environment
+import Options.Applicative
+import qualified Windows.Environment as Env
import qualified Utils
@@ -66,15 +65,15 @@ getLocalDirs = do
fixNtSymbolPath :: Options -> IO ()
fixNtSymbolPath options = do
- oldValue <- Environment.query profile varName
- let oldPaths = Environment.pathSplit $ fromMaybe "" oldValue
+ oldValue <- Env.query profile varName
+ let oldPaths = Env.pathSplit $ fromMaybe "" oldValue
localDirs <- getLocalDirs
let remoteDirs = toRemoteDirs localDirs
let newPaths = union oldPaths $ dirPaths remoteDirs
when (length oldPaths /= length newPaths) $ do
- let newValue = Environment.pathJoin newPaths
+ let newValue = Env.pathJoin newPaths
let promptBanner = Utils.engraveBanner profile varName oldValue newValue
- confirmed <- prompt promptBanner $ Environment.engrave profile varName newValue
+ confirmed <- prompt promptBanner $ Env.engrave profile varName newValue
when confirmed $
createDirs localDirs
where
@@ -82,8 +81,8 @@ fixNtSymbolPath options = do
forAllUsers = optGlobal options
profile = if forAllUsers
- then Environment.AllUsers
- else Environment.CurrentUser
+ then Env.AllUsers
+ else Env.CurrentUser
skipPrompt = optYes options
prompt = if skipPrompt
diff --git a/apps/ListPath.hs b/apps/ListPath.hs
index ace3ede..f33983d 100644
--- a/apps/ListPath.hs
+++ b/apps/ListPath.hs
@@ -11,12 +11,11 @@ import Data.Maybe (fromMaybe)
import System.Directory (doesDirectoryExist)
import System.Environment (lookupEnv)
-import Options.Applicative
-
-import qualified Environment
+import Options.Applicative
+import qualified Windows.Environment as Env
data Options = Options
- { optName :: Environment.VarName
+ { optName :: Env.VarName
} deriving (Eq, Show)
options :: Parser Options
@@ -35,7 +34,7 @@ main = execParser parser >>= listPath
listPath :: Options -> IO ()
listPath options = do
oldValue <- getEnv varName
- let oldPaths = Environment.pathSplit oldValue
+ let oldPaths = Env.pathSplit oldValue
mapM_ printPath oldPaths
where
varName = optName options
diff --git a/apps/RemovePath.hs b/apps/RemovePath.hs
index a594ecd..ecc56c0 100644
--- a/apps/RemovePath.hs
+++ b/apps/RemovePath.hs
@@ -10,17 +10,16 @@ import Control.Monad (void, when)
import Data.List ((\\))
import Data.Maybe (fromJust, isJust)
-import Options.Applicative
-
-import qualified Environment
+import Options.Applicative
+import qualified Windows.Environment as Env
import qualified Utils
data Options = Options
- { optName :: Environment.VarName
+ { optName :: Env.VarName
, optYes :: Bool
, optGlobal :: Bool
- , optPaths :: [Environment.VarValue]
+ , optPaths :: [Env.VarValue]
} deriving (Eq, Show)
options = Options
@@ -50,9 +49,9 @@ main = execParser parser >>= removePath
removePath :: Options -> IO ()
removePath options = do
- removePathFrom Environment.CurrentUser
+ removePathFrom Env.CurrentUser
when forAllUsers $ do
- removePathFrom Environment.AllUsers
+ removePathFrom Env.AllUsers
where
varName = optName options
pathsToRemove = optPaths options
@@ -60,14 +59,14 @@ removePath options = do
forAllUsers = optGlobal options
removePathFrom profile = do
- oldValue <- Environment.query profile varName
+ oldValue <- Env.query profile varName
when (isJust oldValue) $ do
- let oldPaths = Environment.pathSplit $ fromJust oldValue
+ let oldPaths = Env.pathSplit $ fromJust oldValue
let newPaths = oldPaths \\ pathsToRemove
when (length oldPaths /= length newPaths) $ do
- let newValue = Environment.pathJoin newPaths
+ let newValue = Env.pathJoin newPaths
let promptBanner = Utils.engraveBanner profile varName oldValue newValue
- void $ prompt promptBanner $ Environment.engrave profile varName newValue
+ void $ prompt promptBanner $ Env.engrave profile varName newValue
skipPrompt = optYes options
prompt = if skipPrompt
diff --git a/apps/SetEnv.hs b/apps/SetEnv.hs
index 0b95176..a48fbe6 100644
--- a/apps/SetEnv.hs
+++ b/apps/SetEnv.hs
@@ -8,17 +8,16 @@ module Main (main) where
import Control.Monad (void)
-import Options.Applicative hiding (value)
-
-import qualified Environment
+import Options.Applicative
+import qualified Windows.Environment as Env
import qualified Utils
data Options = Options
{ optYes :: Bool
, optGlobal :: Bool
- , optName :: Environment.VarName
- , optValue :: Environment.VarValue
+ , optName :: Env.VarName
+ , optValue :: Env.VarValue
} deriving (Eq, Show)
options :: Parser Options
@@ -48,7 +47,7 @@ main = execParser parser >>= setEnv
fullDesc <> progDesc "Set environment variable"
setEnv :: Options -> IO ()
-setEnv options = void $ prompt confirmationBanner $ Environment.engrave profile varName varValue
+setEnv options = void $ prompt confirmationBanner $ Env.engrave profile varName varValue
where
confirmationBanner = Utils.engraveBanner profile varName Nothing varValue
@@ -57,8 +56,8 @@ setEnv options = void $ prompt confirmationBanner $ Environment.engrave profile
forAllUsers = optGlobal options
profile = if forAllUsers
- then Environment.AllUsers
- else Environment.CurrentUser
+ then Env.AllUsers
+ else Env.CurrentUser
skipPrompt = optYes options
prompt = if skipPrompt
diff --git a/apps/UnsetEnv.hs b/apps/UnsetEnv.hs
index b0ed96a..88101d9 100644
--- a/apps/UnsetEnv.hs
+++ b/apps/UnsetEnv.hs
@@ -8,16 +8,15 @@ module Main (main) where
import Control.Monad (void)
-import Options.Applicative
-
-import qualified Environment
+import Options.Applicative
+import qualified Windows.Environment as Env
import qualified Utils
data Options = Options
{ optYes :: Bool
, optGlobal :: Bool
- , optName :: Environment.VarName
+ , optName :: Env.VarName
} deriving (Eq, Show)
options :: Parser Options
@@ -43,7 +42,7 @@ main = execParser parser >>= unsetEnv
fullDesc <> progDesc "Unset environment variable"
unsetEnv :: Options -> IO ()
-unsetEnv options = void $ prompt confirmationBanner $ Environment.wipe profile varName
+unsetEnv options = void $ prompt confirmationBanner $ Env.wipe profile varName
where
confirmationBanner = Utils.wipeBanner profile varName
@@ -51,8 +50,8 @@ unsetEnv options = void $ prompt confirmationBanner $ Environment.wipe profile v
forAllUsers = optGlobal options
profile = if forAllUsers
- then Environment.AllUsers
- else Environment.CurrentUser
+ then Env.AllUsers
+ else Env.CurrentUser
skipPrompt = optYes options
prompt = if skipPrompt
diff --git a/apps/Utils.hs b/apps/Utils.hs
index 28309d4..e34950f 100644
--- a/apps/Utils.hs
+++ b/apps/Utils.hs
@@ -18,7 +18,7 @@ import Data.Char (toLower)
import System.IO (hFlush, stdout)
import Text.Printf (printf)
-import Environment (Profile, profileKeyPath, VarName, VarValue)
+import Windows.Environment (Profile, profileKeyPath, VarName, VarValue)
prompt :: String -> IO String
prompt banner = do