2017-01-30 20:41:29 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2017 Joey Hess <id@joeyh.name>
|
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2017-01-30 20:41:29 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Config where
|
|
|
|
|
|
|
|
import Command
|
|
|
|
import Logs.Config
|
2017-02-27 20:08:16 +00:00
|
|
|
import Config
|
2017-01-30 20:41:29 +00:00
|
|
|
|
|
|
|
cmd :: Command
|
2017-02-16 17:24:16 +00:00
|
|
|
cmd = noMessages $ command "config" SectionSetup
|
|
|
|
"configuration stored in git-annex branch"
|
2017-01-30 20:41:29 +00:00
|
|
|
paramNothing (seek <$$> optParser)
|
|
|
|
|
|
|
|
data Action
|
|
|
|
= SetConfig ConfigName ConfigValue
|
|
|
|
| GetConfig ConfigName
|
|
|
|
| UnsetConfig ConfigName
|
|
|
|
|
|
|
|
type Name = String
|
|
|
|
type Value = String
|
|
|
|
|
|
|
|
optParser :: CmdParamsDesc -> Parser Action
|
|
|
|
optParser _ = setconfig <|> getconfig <|> unsetconfig
|
|
|
|
where
|
|
|
|
setconfig = SetConfig
|
|
|
|
<$> strOption
|
|
|
|
( long "set"
|
|
|
|
<> help "set configuration"
|
|
|
|
<> metavar paramName
|
|
|
|
)
|
|
|
|
<*> strArgument
|
|
|
|
( metavar paramValue
|
|
|
|
)
|
|
|
|
getconfig = GetConfig <$> strOption
|
|
|
|
( long "get"
|
|
|
|
<> help "get configuration"
|
|
|
|
<> metavar paramName
|
|
|
|
)
|
|
|
|
unsetconfig = UnsetConfig <$> strOption
|
|
|
|
( long "unset"
|
|
|
|
<> help "unset configuration"
|
|
|
|
<> metavar paramName
|
|
|
|
)
|
|
|
|
|
|
|
|
seek :: Action -> CommandSeek
|
|
|
|
seek (SetConfig name val) = commandAction $ do
|
2017-02-16 17:24:16 +00:00
|
|
|
allowMessages
|
2017-11-28 18:40:26 +00:00
|
|
|
showStart' name (Just val)
|
2017-01-30 20:41:29 +00:00
|
|
|
next $ next $ do
|
|
|
|
setGlobalConfig name val
|
2017-02-27 20:08:16 +00:00
|
|
|
setConfig (ConfigKey name) val
|
2017-01-30 20:41:29 +00:00
|
|
|
return True
|
|
|
|
seek (UnsetConfig name) = commandAction $ do
|
2017-02-16 17:24:16 +00:00
|
|
|
allowMessages
|
2017-11-28 18:40:26 +00:00
|
|
|
showStart' name (Just "unset")
|
2017-01-30 20:41:29 +00:00
|
|
|
next $ next $ do
|
|
|
|
unsetGlobalConfig name
|
2017-02-27 20:08:16 +00:00
|
|
|
unsetConfig (ConfigKey name)
|
2017-01-30 20:41:29 +00:00
|
|
|
return True
|
2017-12-05 19:00:50 +00:00
|
|
|
seek (GetConfig name) = commandAction $
|
|
|
|
getGlobalConfig name >>= \case
|
2017-01-30 20:41:29 +00:00
|
|
|
Nothing -> stop
|
|
|
|
Just v -> do
|
|
|
|
liftIO $ putStrLn v
|
|
|
|
stop
|