aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/apps/FixNtSymbolPath.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/FixNtSymbolPath.hs
parentREADME update (diff)
downloadwindows-env-8653780e04df0ad0d24b5be15a98bb0dcb01ca30.tar.gz
windows-env-8653780e04df0ad0d24b5be15a98bb0dcb01ca30.zip
add command line options to skip prompts
Diffstat (limited to 'apps/FixNtSymbolPath.hs')
-rw-r--r--apps/FixNtSymbolPath.hs40
1 files changed, 35 insertions, 5 deletions
diff --git a/apps/FixNtSymbolPath.hs b/apps/FixNtSymbolPath.hs
index f3d465e..636e93b 100644
--- a/apps/FixNtSymbolPath.hs
+++ b/apps/FixNtSymbolPath.hs
@@ -12,8 +12,27 @@ import Data.Maybe (fromMaybe)
import System.Directory (createDirectoryIfMissing, getCurrentDirectory)
import System.FilePath (combine)
+import Options.Applicative
+
import qualified Environment
+data Options = Options
+ { optYes :: Bool
+ , optGlobal :: Bool
+ } deriving (Eq, Show)
+
+options :: Parser Options
+options = Options
+ <$> optYesDesc
+ <*> optGlobalDesc
+ where
+ optYesDesc = switch $
+ long "yes" <> short 'y' <>
+ help "Skip confirmation prompt"
+ optGlobalDesc = switch $
+ long "global" <> short 'g' <>
+ help "Set up for all users"
+
getRemoteSymbolsDirectoryPath :: IO String
getRemoteSymbolsDirectoryPath = do
localPath <- getLocalPath
@@ -32,19 +51,30 @@ getPdbsDirectoryPath = do
createDirectoryIfMissing True path
return path
-fixNtSymbolPath :: IO ()
-fixNtSymbolPath = do
+fixNtSymbolPath :: Options -> IO ()
+fixNtSymbolPath options = do
oldValue <- Environment.query env varName
let oldPaths = Environment.pathSplit $ fromMaybe "" oldValue
pathsToAdd <- addPaths
let newPaths = union oldPaths pathsToAdd
when (length oldPaths /= length newPaths) $ do
let newValue = Environment.pathJoin newPaths
- Environment.engrave env varName newValue
+ engrave env varName newValue
where
- env = Environment.CurrentUser
varName = "_NT_SYMBOL_PATH"
addPaths = sequence [getRemoteSymbolsDirectoryPath, getPdbsDirectoryPath]
+ forAllUsers = optGlobal options
+ env | forAllUsers = Environment.AllUsers
+ | otherwise = Environment.CurrentUser
+
+ skipPrompt = optYes options
+ engrave
+ | skipPrompt = Environment.engrave
+ | otherwise = Environment.engraveWithPrompt
+
main :: IO ()
-main = fixNtSymbolPath
+main = execParser parser >>= fixNtSymbolPath
+ where
+ parser = info (helper <*> options) $
+ fullDesc <> progDesc "Set up your _NT_SYMBOL_PATH"