aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/apps/AddPath.hs
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-07-18 00:09:44 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-07-18 00:09:44 +0300
commit14d1ee026b9f2dded1eb1adc51e50f6b779b4aa4 (patch)
tree60daf05b8eafaec8ae4d4d90ac6cc59b4a1af22a /apps/AddPath.hs
parentrefactoring (diff)
downloadwindows-env-14d1ee026b9f2dded1eb1adc51e50f6b779b4aa4.tar.gz
windows-env-14d1ee026b9f2dded1eb1adc51e50f6b779b4aa4.zip
refactoring
Diffstat (limited to 'apps/AddPath.hs')
-rw-r--r--apps/AddPath.hs24
1 files changed, 13 insertions, 11 deletions
diff --git a/apps/AddPath.hs b/apps/AddPath.hs
index 9c6c245..6103d1d 100644
--- a/apps/AddPath.hs
+++ b/apps/AddPath.hs
@@ -6,19 +6,22 @@
module Main (main) where
-import Control.Monad (when)
+import Control.Monad (void, when)
import Data.List (union)
import Data.Maybe (fromMaybe)
+import Text.Printf (printf)
import Options.Applicative
import qualified Environment
+import qualified Utils
+
data Options = Options
- { optName :: String
+ { optName :: Environment.VarName
, optYes :: Bool
, optGlobal :: Bool
- , optPaths :: [String]
+ , optPaths :: [Environment.VarValue]
} deriving (Eq, Show)
options :: Parser Options
@@ -49,24 +52,23 @@ main = execParser parser >>= addPath
addPath :: Options -> IO ()
addPath options = do
- oldValue <- query
+ oldValue <- Environment.query profile varName
let oldPaths = Environment.pathSplit $ fromMaybe "" oldValue
let newPaths = union oldPaths pathsToAdd
when (length oldPaths /= length newPaths) $ do
let newValue = Environment.pathJoin newPaths
- engrave newValue
+ let promptBanner = Utils.engraveBanner profile varName oldValue newValue
+ void $ prompt promptBanner $ Environment.engrave profile varName newValue
where
varName = optName options
pathsToAdd = optPaths options
forAllUsers = optGlobal options
- env = if forAllUsers
+ profile = if forAllUsers
then Environment.AllUsers
else Environment.CurrentUser
- query = Environment.query env varName
-
skipPrompt = optYes options
- engrave value = if skipPrompt
- then Environment.engrave env varName value
- else Environment.engravePrompt env varName value >> return ()
+ prompt = if skipPrompt
+ then const Utils.withoutPrompt
+ else Utils.withPrompt