From 14d1ee026b9f2dded1eb1adc51e50f6b779b4aa4 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 18 Jul 2016 00:09:44 +0300 Subject: refactoring --- apps/UnsetEnv.hs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'apps/UnsetEnv.hs') diff --git a/apps/UnsetEnv.hs b/apps/UnsetEnv.hs index e4cbeac..b0ed96a 100644 --- a/apps/UnsetEnv.hs +++ b/apps/UnsetEnv.hs @@ -6,14 +6,18 @@ module Main (main) where +import Control.Monad (void) + import Options.Applicative import qualified Environment +import qualified Utils + data Options = Options { optYes :: Bool , optGlobal :: Bool - , optName :: String + , optName :: Environment.VarName } deriving (Eq, Show) options :: Parser Options @@ -39,16 +43,18 @@ main = execParser parser >>= unsetEnv fullDesc <> progDesc "Unset environment variable" unsetEnv :: Options -> IO () -unsetEnv options = wipe +unsetEnv options = void $ prompt confirmationBanner $ Environment.wipe profile varName where + confirmationBanner = Utils.wipeBanner profile varName + varName = optName options forAllUsers = optGlobal options - env = if forAllUsers + profile = if forAllUsers then Environment.AllUsers else Environment.CurrentUser skipPrompt = optYes options - wipe = if skipPrompt - then Environment.wipe env varName - else Environment.wipePrompt env varName >> return () + prompt = if skipPrompt + then const Utils.withoutPrompt + else Utils.withPrompt -- cgit v1.2.3