aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/apps/RemovePath.hs
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-07-17 15:47:51 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-07-17 15:47:51 +0300
commit8653780e04df0ad0d24b5be15a98bb0dcb01ca30 (patch)
tree8137ce258398a6c422dc36b8751ffe4f1fc05364 /apps/RemovePath.hs
parentREADME update (diff)
downloadwindows-env-8653780e04df0ad0d24b5be15a98bb0dcb01ca30.tar.gz
windows-env-8653780e04df0ad0d24b5be15a98bb0dcb01ca30.zip
add command line options to skip prompts
Diffstat (limited to 'apps/RemovePath.hs')
-rw-r--r--apps/RemovePath.hs28
1 files changed, 20 insertions, 8 deletions
diff --git a/apps/RemovePath.hs b/apps/RemovePath.hs
index 87c60a4..8c2bcef 100644
--- a/apps/RemovePath.hs
+++ b/apps/RemovePath.hs
@@ -16,24 +16,29 @@ import qualified Environment
data Options = Options
{ optName :: String
+ , optYes :: Bool
, optGlobal :: Bool
, optPaths :: [String]
} deriving (Eq, Show)
options = Options
<$> optNameDesc
+ <*> optYesDesc
<*> optGlobalDesc
<*> optPathsDesc
where
optNameDesc = strOption $
long "name" <> short 'n' <> metavar "NAME" <> value "PATH" <>
- help "Specify variable name ('PATH' by default)"
+ help "Variable name ('PATH' by default)"
+ optYesDesc = switch $
+ long "yes" <> short 'y' <>
+ help "Skip confirmation prompt"
optGlobalDesc = switch $
long "global" <> short 'g' <>
- help "Whether to remove for all users"
+ help "Remove for all users"
optPathsDesc = many $ argument str $
metavar "PATH" <>
- help "Directory path(s)"
+ help "Directories to remove"
main :: IO ()
main = execParser parser >>= removePath
@@ -43,18 +48,25 @@ main = execParser parser >>= removePath
removePath :: Options -> IO ()
removePath options = do
- removePathFrom Environment.CurrentUser options
- when (optGlobal options) $ do
- removePathFrom Environment.AllUsers options
+ removePathFrom Environment.CurrentUser
+ when forAllUsers $ do
+ removePathFrom Environment.AllUsers
where
varName = optName options
pathsToRemove = optPaths options
- removePathFrom env options = do
+ forAllUsers = optGlobal options
+
+ removePathFrom env = do
oldValue <- Environment.query env varName
when (isJust oldValue) $ do
let oldPaths = Environment.pathSplit $ fromJust oldValue
let newPaths = oldPaths \\ pathsToRemove
when (length oldPaths /= length newPaths) $ do
let newValue = Environment.pathJoin newPaths
- Environment.engraveWithPrompt env varName newValue
+ engrave env varName newValue
+
+ skipPrompt = optYes options
+ engrave
+ | skipPrompt = Environment.engrave
+ | otherwise = Environment.engraveWithPrompt