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
|
* initremote: Avoid creating a remote that is not encrypted when gpg is
|
||||||
broken.
|
broken.
|
||||||
* Support --json and --json-error-messages in many more commands
|
* Support --json and --json-error-messages in many more commands
|
||||||
(addunused, dead, describe, dropunused, enableremote, expire, fix,
|
(addunused, configremote, dead, describe, dropunused, enableremote,
|
||||||
importfeed, init, initremote, log, merge, migrate, reinit, reinject,
|
expire, fix, importfeed, init, initremote, log, merge, migrate, reinit,
|
||||||
rekey, renameremote, rmurl, semitrust, setpresentkey, trust, unannex,
|
reinject, rekey, renameremote, rmurl, semitrust, setpresentkey, trust,
|
||||||
undo, untrust, unused, upgrade)
|
unannex, undo, untrust, unused, upgrade)
|
||||||
* log: When --raw-date is used, display only seconds from the epoch, as
|
* log: When --raw-date is used, display only seconds from the epoch, as
|
||||||
documented, omitting a trailing "s" that was included in the output
|
documented, omitting a trailing "s" that was included in the output
|
||||||
before.
|
before.
|
||||||
|
|
|
@ -20,41 +20,43 @@ import Command.EnableRemote (unknownNameError, startSpecialRemote', PerformSpeci
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
|
|
||||||
cmd :: Command
|
cmd :: Command
|
||||||
cmd = command "configremote" SectionSetup
|
cmd = withAnnexOptions [jsonOptions] $
|
||||||
"changes special remote configuration"
|
command "configremote" SectionSetup
|
||||||
(paramPair paramName $ paramOptional $ paramRepeating paramParamValue)
|
"changes special remote configuration"
|
||||||
(withParams seek)
|
(paramPair paramName $ paramOptional $ paramRepeating paramParamValue)
|
||||||
|
(withParams seek)
|
||||||
|
|
||||||
seek :: CmdParams -> CommandSeek
|
seek :: CmdParams -> CommandSeek
|
||||||
seek = withWords (commandAction . start)
|
seek = withWords (commandAction . start)
|
||||||
|
|
||||||
start :: [String] -> CommandStart
|
start :: [String] -> CommandStart
|
||||||
start [] = unknownNameError "Specify the remote to configure."
|
start [] = unknownNameError "Specify the remote to configure."
|
||||||
start (name:rest) = do
|
start (name:inputconfig) = deadLast name $
|
||||||
cfg <- safeConfig rest
|
startSpecialRemote (checkSafeConfig inputconfig) name
|
||||||
deadLast name $ startSpecialRemote name cfg
|
(Logs.Remote.keyValToConfig Proposed inputconfig)
|
||||||
|
|
||||||
{- Since this command stores config without calling the remote's setup
|
{- 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
|
- method to validate it, it can only be used on fields that are known to
|
||||||
- be safe to change in all remotes. -}
|
- be safe to change in all remotes. -}
|
||||||
safeConfig :: [String] -> Annex Remote.RemoteConfig
|
checkSafeConfig :: [String] -> Annex ()
|
||||||
safeConfig cs = do
|
checkSafeConfig cs = do
|
||||||
let rc = Logs.Remote.keyValToConfig Proposed cs
|
let rc = Logs.Remote.keyValToConfig Proposed cs
|
||||||
forM_ (M.keys rc) $ \k ->
|
forM_ (M.keys rc) $ \k ->
|
||||||
when (fromProposedAccepted k `notElem` safefields) $
|
when (fromProposedAccepted k `notElem` safefields) $
|
||||||
giveup $ "Cannot change field \"" ++ fromProposedAccepted k ++ "\" with this command. Use git-annex enableremote instead."
|
giveup $ "Cannot change field \"" ++ fromProposedAccepted k ++ "\" with this command. Use git-annex enableremote instead."
|
||||||
case SpecialRemote.parseRemoteConfig rc (Remote.RemoteConfigParser ps Nothing) of
|
case SpecialRemote.parseRemoteConfig rc (Remote.RemoteConfigParser ps Nothing) of
|
||||||
Left err -> giveup err
|
Left err -> giveup err
|
||||||
Right _ -> return rc
|
Right _ -> return ()
|
||||||
where
|
where
|
||||||
ps = [ SpecialRemote.autoEnableFieldParser ]
|
ps = [ SpecialRemote.autoEnableFieldParser ]
|
||||||
safefields = [ fromProposedAccepted SpecialRemote.autoEnableField ]
|
safefields = [ fromProposedAccepted SpecialRemote.autoEnableField ]
|
||||||
|
|
||||||
startSpecialRemote :: Git.RemoteName -> Remote.RemoteConfig -> [(UUID, Remote.RemoteConfig, Maybe (SpecialRemote.ConfigFrom UUID))] -> CommandStart
|
startSpecialRemote :: Annex () -> Git.RemoteName -> Remote.RemoteConfig -> [(UUID, Remote.RemoteConfig, Maybe (SpecialRemote.ConfigFrom UUID))] -> CommandStart
|
||||||
startSpecialRemote = startSpecialRemote' "configremote" performSpecialRemote
|
startSpecialRemote = startSpecialRemote' "configremote" . performSpecialRemote
|
||||||
|
|
||||||
performSpecialRemote :: PerformSpecialRemote
|
performSpecialRemote :: Annex () -> PerformSpecialRemote
|
||||||
performSpecialRemote _ u _ c _ mcu = do
|
performSpecialRemote precheck _ u _ c _ mcu = do
|
||||||
|
precheck
|
||||||
case mcu of
|
case mcu of
|
||||||
Nothing -> Logs.Remote.configSet u c
|
Nothing -> Logs.Remote.configSet u c
|
||||||
Just (SpecialRemote.ConfigFrom cu) ->
|
Just (SpecialRemote.ConfigFrom cu) ->
|
||||||
|
|
|
@ -41,9 +41,6 @@ These commands have been updated to support --json:
|
||||||
* git-annex-upgrade
|
* git-annex-upgrade
|
||||||
* git-annex-initremote
|
* git-annex-initremote
|
||||||
* git-annex-enableremote
|
* git-annex-enableremote
|
||||||
|
|
||||||
Provisional list of commands that don't support --json and maybe should:
|
|
||||||
|
|
||||||
* git-annex-configremote
|
* git-annex-configremote
|
||||||
|
|
||||||
These commands could support json, but I punted:
|
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:
|
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,
|
* git-annex-contentlocation, git-annex-lookupkey, git-annex-calckey,
|
||||||
(plumbing, output already machine parseable)
|
(plumbing, output already machine parseable)
|
||||||
* git-annex-setkey (plumbing)
|
* git-annex-setkey (plumbing)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue