aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/apps/AddPath.hs
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-07-17 18:24:12 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-07-17 18:24:12 +0300
commitd854f16486913af7fb70e4ff251a29d5cf2d7323 (patch)
treecffae3dc6f90ff96da9b11ddc57d7bf43bc97ad1 /apps/AddPath.hs
parentupdate project description (diff)
downloadwindows-env-d854f16486913af7fb70e4ff251a29d5cf2d7323.tar.gz
windows-env-d854f16486913af7fb70e4ff251a29d5cf2d7323.zip
refactoring
Diffstat (limited to '')
-rw-r--r--apps/AddPath.hs12
1 files changed, 7 insertions, 5 deletions
diff --git a/apps/AddPath.hs b/apps/AddPath.hs
index 40fa785..a3004a8 100644
--- a/apps/AddPath.hs
+++ b/apps/AddPath.hs
@@ -49,12 +49,12 @@ main = execParser parser >>= addPath
addPath :: Options -> IO ()
addPath options = do
- oldValue <- Environment.query env varName
+ oldValue <- query
let oldPaths = Environment.pathSplit $ fromMaybe "" oldValue
let newPaths = union oldPaths pathsToAdd
when (length oldPaths /= length newPaths) $ do
let newValue = Environment.pathJoin newPaths
- engrave env varName newValue
+ engrave newValue
where
varName = optName options
pathsToAdd = optPaths options
@@ -63,7 +63,9 @@ addPath options = do
env | forAllUsers = Environment.AllUsers
| otherwise = Environment.CurrentUser
+ query = Environment.query env varName
+
skipPrompt = optYes options
- engrave
- | skipPrompt = Environment.engrave
- | otherwise = Environment.engraveWithPrompt
+ engrave value = if skipPrompt
+ then Environment.engrave env varName value
+ else Environment.engravePrompt env varName value >> return ()