2023-04-18 19:30:49 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2023 Joey Hess <id@joeyh.name>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
|
|
|
module Command.ConfigRemote where
|
|
|
|
|
|
|
|
import Command
|
|
|
|
import qualified Logs.Remote
|
|
|
|
import qualified Git.Types as Git
|
|
|
|
import qualified Annex.SpecialRemote as SpecialRemote
|
|
|
|
import qualified Types.Remote as Remote
|
|
|
|
import Types.ProposedAccepted
|
|
|
|
import Command.EnableRemote (unknownNameError, startSpecialRemote', PerformSpecialRemote, deadLast)
|
|
|
|
|
|
|
|
import qualified Data.Map as M
|
|
|
|
|
|
|
|
cmd :: Command
|
2023-05-10 18:19:32 +00:00
|
|
|
cmd = withAnnexOptions [jsonOptions] $
|
|
|
|
command "configremote" SectionSetup
|
|
|
|
"changes special remote configuration"
|
|
|
|
(paramPair paramName $ paramOptional $ paramRepeating paramParamValue)
|
|
|
|
(withParams seek)
|
2023-04-18 19:30:49 +00:00
|
|
|
|
|
|
|
seek :: CmdParams -> CommandSeek
|
|
|
|
seek = withWords (commandAction . start)
|
|
|
|
|
|
|
|
start :: [String] -> CommandStart
|
|
|
|
start [] = unknownNameError "Specify the remote to configure."
|
2023-05-10 18:19:32 +00:00
|
|
|
start (name:inputconfig) = deadLast name $
|
|
|
|
startSpecialRemote (checkSafeConfig inputconfig) name
|
|
|
|
(Logs.Remote.keyValToConfig Proposed inputconfig)
|
2023-04-18 19:30:49 +00:00
|
|
|
|
|
|
|
{- Since this command stores config without calling the remote's setup
|
|
|
|
- method to validate it, it can only be used on fields that are known to
|
|
|
|
- be safe to change in all remotes. -}
|
2023-05-10 18:19:32 +00:00
|
|
|
checkSafeConfig :: [String] -> Annex ()
|
|
|
|
checkSafeConfig cs = do
|
2023-04-18 19:30:49 +00:00
|
|
|
let rc = Logs.Remote.keyValToConfig Proposed cs
|
|
|
|
forM_ (M.keys rc) $ \k ->
|
|
|
|
when (fromProposedAccepted k `notElem` safefields) $
|
|
|
|
giveup $ "Cannot change field \"" ++ fromProposedAccepted k ++ "\" with this command. Use git-annex enableremote instead."
|
|
|
|
case SpecialRemote.parseRemoteConfig rc (Remote.RemoteConfigParser ps Nothing) of
|
|
|
|
Left err -> giveup err
|
2023-05-10 18:19:32 +00:00
|
|
|
Right _ -> return ()
|
2023-04-18 19:30:49 +00:00
|
|
|
where
|
|
|
|
ps = [ SpecialRemote.autoEnableFieldParser ]
|
|
|
|
safefields = [ fromProposedAccepted SpecialRemote.autoEnableField ]
|
|
|
|
|
2023-05-10 18:19:32 +00:00
|
|
|
startSpecialRemote :: Annex () -> Git.RemoteName -> Remote.RemoteConfig -> [(UUID, Remote.RemoteConfig, Maybe (SpecialRemote.ConfigFrom UUID))] -> CommandStart
|
|
|
|
startSpecialRemote = startSpecialRemote' "configremote" . performSpecialRemote
|
2023-04-18 19:30:49 +00:00
|
|
|
|
2023-05-10 18:19:32 +00:00
|
|
|
performSpecialRemote :: Annex () -> PerformSpecialRemote
|
|
|
|
performSpecialRemote precheck _ u _ c _ mcu = do
|
|
|
|
precheck
|
2023-04-18 19:30:49 +00:00
|
|
|
case mcu of
|
|
|
|
Nothing -> Logs.Remote.configSet u c
|
|
|
|
Just (SpecialRemote.ConfigFrom cu) ->
|
|
|
|
Logs.Remote.configSet cu c
|
|
|
|
next $ return True
|