From 8653780e04df0ad0d24b5be15a98bb0dcb01ca30 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 17 Jul 2016 15:47:51 +0300 Subject: add command line options to skip prompts --- apps/UnsetEnv.hs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'apps/UnsetEnv.hs') 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 -- cgit v1.2.3