configremote: Support --json and --json-error-messages
Seems unlikely to be too useful, but who knows. Moved the checkSafeConfig call to happen after an action is started, so it will be captured by --json-error-messages Sponsored-By: the NIH-funded NICEMAN (ReproNim TR&D3) project
This commit is contained in:
parent
a242eabc7a
commit
de84abb210
3 changed files with 22 additions and 21 deletions
|
@ -38,10 +38,10 @@ git-annex (10.20230408) UNRELEASED; urgency=medium
|
|||
* initremote: Avoid creating a remote that is not encrypted when gpg is
|
||||
broken.
|
||||
* Support --json and --json-error-messages in many more commands
|
||||
(addunused, dead, describe, dropunused, enableremote, expire, fix,
|
||||
importfeed, init, initremote, log, merge, migrate, reinit, reinject,
|
||||
rekey, renameremote, rmurl, semitrust, setpresentkey, trust, unannex,
|
||||
undo, untrust, unused, upgrade)
|
||||
(addunused, configremote, dead, describe, dropunused, enableremote,
|
||||
expire, fix, importfeed, init, initremote, log, merge, migrate, reinit,
|
||||
reinject, rekey, renameremote, rmurl, semitrust, setpresentkey, trust,
|
||||
unannex, undo, untrust, unused, upgrade)
|
||||
* log: When --raw-date is used, display only seconds from the epoch, as
|
||||
documented, omitting a trailing "s" that was included in the output
|
||||
before.
|
||||
|
|
|
@ -20,41 +20,43 @@ import Command.EnableRemote (unknownNameError, startSpecialRemote', PerformSpeci
|
|||
import qualified Data.Map as M
|
||||
|
||||
cmd :: Command
|
||||
cmd = command "configremote" SectionSetup
|
||||
"changes special remote configuration"
|
||||
(paramPair paramName $ paramOptional $ paramRepeating paramParamValue)
|
||||
(withParams seek)
|
||||
cmd = withAnnexOptions [jsonOptions] $
|
||||
command "configremote" SectionSetup
|
||||
"changes special remote configuration"
|
||||
(paramPair paramName $ paramOptional $ paramRepeating paramParamValue)
|
||||
(withParams seek)
|
||||
|
||||
seek :: CmdParams -> CommandSeek
|
||||
seek = withWords (commandAction . start)
|
||||
|
||||
start :: [String] -> CommandStart
|
||||
start [] = unknownNameError "Specify the remote to configure."
|
||||
start (name:rest) = do
|
||||
cfg <- safeConfig rest
|
||||
deadLast name $ startSpecialRemote name cfg
|
||||
start (name:inputconfig) = deadLast name $
|
||||
startSpecialRemote (checkSafeConfig inputconfig) name
|
||||
(Logs.Remote.keyValToConfig Proposed inputconfig)
|
||||
|
||||
{- 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. -}
|
||||
safeConfig :: [String] -> Annex Remote.RemoteConfig
|
||||
safeConfig cs = do
|
||||
checkSafeConfig :: [String] -> Annex ()
|
||||
checkSafeConfig cs = do
|
||||
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
|
||||
Right _ -> return rc
|
||||
Right _ -> return ()
|
||||
where
|
||||
ps = [ SpecialRemote.autoEnableFieldParser ]
|
||||
safefields = [ fromProposedAccepted SpecialRemote.autoEnableField ]
|
||||
|
||||
startSpecialRemote :: Git.RemoteName -> Remote.RemoteConfig -> [(UUID, Remote.RemoteConfig, Maybe (SpecialRemote.ConfigFrom UUID))] -> CommandStart
|
||||
startSpecialRemote = startSpecialRemote' "configremote" performSpecialRemote
|
||||
startSpecialRemote :: Annex () -> Git.RemoteName -> Remote.RemoteConfig -> [(UUID, Remote.RemoteConfig, Maybe (SpecialRemote.ConfigFrom UUID))] -> CommandStart
|
||||
startSpecialRemote = startSpecialRemote' "configremote" . performSpecialRemote
|
||||
|
||||
performSpecialRemote :: PerformSpecialRemote
|
||||
performSpecialRemote _ u _ c _ mcu = do
|
||||
performSpecialRemote :: Annex () -> PerformSpecialRemote
|
||||
performSpecialRemote precheck _ u _ c _ mcu = do
|
||||
precheck
|
||||
case mcu of
|
||||
Nothing -> Logs.Remote.configSet u c
|
||||
Just (SpecialRemote.ConfigFrom cu) ->
|
||||
|
|
|
@ -41,9 +41,6 @@ These commands have been updated to support --json:
|
|||
* git-annex-upgrade
|
||||
* git-annex-initremote
|
||||
* git-annex-enableremote
|
||||
|
||||
Provisional list of commands that don't support --json and maybe should:
|
||||
|
||||
* git-annex-configremote
|
||||
|
||||
These commands could support json, but I punted:
|
||||
|
@ -57,6 +54,8 @@ These commands could support json, but I punted:
|
|||
|
||||
These commands have been reviewed and should not support json:
|
||||
|
||||
(Discussion welcome of course if you disagree..)
|
||||
|
||||
* git-annex-contentlocation, git-annex-lookupkey, git-annex-calckey,
|
||||
(plumbing, output already machine parseable)
|
||||
* git-annex-setkey (plumbing)
|
||||
|
|
Loading…
Reference in a new issue