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