diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2016-07-13 03:28:51 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2016-07-13 03:28:51 +0300 |
commit | 54db9a94963826141c79ffe30df0453f85a117c8 (patch) | |
tree | 22190418728ed381c1c0c45c2d58c5acfda06423 /apps/SetEnv.hs | |
parent | reorder imports (diff) | |
download | windows-env-54db9a94963826141c79ffe30df0453f85a117c8.tar.gz windows-env-54db9a94963826141c79ffe30df0453f85a117c8.zip |
bugfix + refactoring
Diffstat (limited to 'apps/SetEnv.hs')
-rw-r--r-- | apps/SetEnv.hs | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/apps/SetEnv.hs b/apps/SetEnv.hs index fad7526..812975b 100644 --- a/apps/SetEnv.hs +++ b/apps/SetEnv.hs @@ -11,24 +11,24 @@ import Options.Applicative hiding (value) import qualified Environment data Options = Options - { global :: Bool - , name :: String - , value :: String + { optGlobal :: Bool + , optName :: String + , optValue :: String } deriving (Eq, Show) options :: Parser Options options = Options - <$> globalOption - <*> nameArg - <*> valueArg + <$> optGlobalDesc + <*> optNameDesc + <*> optValueDesc where - globalOption = switch $ + optGlobalDesc = switch $ long "global" <> short 'g' <> help "Whether to set for all users" - nameArg = argument str $ + optNameDesc = argument str $ metavar "NAME" <> help "Variable name" - valueArg = argument str $ + optValueDesc = argument str $ metavar "VALUE" <> help "Variable value" @@ -39,7 +39,9 @@ main = execParser parser >>= setEnv fullDesc <> progDesc "Set environment variables" setEnv :: Options -> IO () -setEnv options = Environment.engraveWithPrompt env (name options) (value options) +setEnv options = Environment.engraveWithPrompt env varName varValue where - env | global options = Environment.AllUsers - | otherwise = Environment.CurrentUser + env | optGlobal options = Environment.AllUsers + | otherwise = Environment.CurrentUser + varName = optName options + varValue = optValue options |