aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/apps/UnsetEnv.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/UnsetEnv.hs
parentREADME update (diff)
downloadwindows-env-8653780e04df0ad0d24b5be15a98bb0dcb01ca30.tar.gz
windows-env-8653780e04df0ad0d24b5be15a98bb0dcb01ca30.zip
add command line options to skip prompts
Diffstat (limited to 'apps/UnsetEnv.hs')
-rw-r--r--apps/UnsetEnv.hs26
1 files changed, 19 insertions, 7 deletions
diff --git a/apps/UnsetEnv.hs b/apps/UnsetEnv.hs
index f7bf0b2..14111d2 100644
--- a/apps/UnsetEnv.hs
+++ b/apps/UnsetEnv.hs
@@ -11,18 +11,23 @@ import Options.Applicative
import qualified Environment
data Options = Options
- { optGlobal :: Bool
+ { optYes :: Bool
+ , optGlobal :: Bool
, optName :: String
} deriving (Eq, Show)
options :: Parser Options
options = Options
- <$> optGlobalDesc
+ <$> optYes
+ <*> optGlobalDesc
<*> optNameDesc
where
+ optYes = switch $
+ long "yes" <> short 'y' <>
+ help "Skip confirmation prompt"
optGlobalDesc = switch $
long "global" <> short 'g' <>
- help "Whether to unset for all users"
+ help "Unset for all users"
optNameDesc = argument str $
metavar "NAME" <>
help "Variable name"
@@ -31,11 +36,18 @@ main :: IO ()
main = execParser parser >>= unsetEnv
where
parser = info (helper <*> options) $
- fullDesc <> progDesc "Unset environment variables"
+ fullDesc <> progDesc "Unset environment variable"
unsetEnv :: Options -> IO ()
-unsetEnv options = Environment.wipeWithPrompt env varName
+unsetEnv options = wipe env varName
where
- env | optGlobal options = Environment.AllUsers
- | otherwise = Environment.CurrentUser
varName = optName options
+
+ forAllUsers = optGlobal options
+ env | forAllUsers = Environment.AllUsers
+ | otherwise = Environment.CurrentUser
+
+ skipPrompt = optYes options
+ wipe
+ | skipPrompt = Environment.wipe
+ | otherwise = Environment.wipeWithPrompt