aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/apps/AddPath.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/AddPath.hs
parentREADME update (diff)
downloadwindows-env-8653780e04df0ad0d24b5be15a98bb0dcb01ca30.tar.gz
windows-env-8653780e04df0ad0d24b5be15a98bb0dcb01ca30.zip
add command line options to skip prompts
Diffstat (limited to 'apps/AddPath.hs')
-rw-r--r--apps/AddPath.hs24
1 files changed, 18 insertions, 6 deletions
diff --git a/apps/AddPath.hs b/apps/AddPath.hs
index aeb5ee5..40fa785 100644
--- a/apps/AddPath.hs
+++ b/apps/AddPath.hs
@@ -16,6 +16,7 @@ import qualified Environment
data Options = Options
{ optName :: String
+ , optYes :: Bool
, optGlobal :: Bool
, optPaths :: [String]
} deriving (Eq, Show)
@@ -23,18 +24,22 @@ data Options = Options
options :: Parser Options
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 add for all users"
+ help "Add for all users"
optPathsDesc = many $ argument str $
metavar "PATH" <>
- help "Directory path(s)"
+ help "Directories to add"
main :: IO ()
main = execParser parser >>= addPath
@@ -49,9 +54,16 @@ addPath options = do
let newPaths = union oldPaths pathsToAdd
when (length oldPaths /= length newPaths) $ do
let newValue = Environment.pathJoin newPaths
- Environment.engraveWithPrompt env varName newValue
+ engrave env varName newValue
where
- env | optGlobal options = Environment.AllUsers
- | otherwise = Environment.CurrentUser
varName = optName options
pathsToAdd = optPaths options
+
+ forAllUsers = optGlobal options
+ env | forAllUsers = Environment.AllUsers
+ | otherwise = Environment.CurrentUser
+
+ skipPrompt = optYes options
+ engrave
+ | skipPrompt = Environment.engrave
+ | otherwise = Environment.engraveWithPrompt