initremote --describe-other-params

Does not yet include descriptions from external special remote programs.
This commit is contained in:
Joey Hess 2020-01-20 16:05:51 -04:00
parent 2f8822307f
commit aa949bbb7d
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
6 changed files with 60 additions and 20 deletions

View file

@ -72,7 +72,10 @@ findType config = maybe unspecified (specified . fromProposedAccepted) $
where where
unspecified = Left "Specify the type of remote with type=" unspecified = Left "Specify the type of remote with type="
specified s = case filter (findtype s) remoteTypes of specified s = case filter (findtype s) remoteTypes of
[] -> Left $ "Unknown remote type " ++ s [] -> Left $ "Unknown remote type " ++ s
++ " (pick from: "
++ intercalate " " (map typename remoteTypes)
++ ")"
(t:_) -> Right t (t:_) -> Right t
findtype s i = typename i == s findtype s i = typename i == s

View file

@ -6,10 +6,12 @@ git-annex (7.20191231) UNRELEASED; urgency=medium
* reinject --known: Fix bug that prevented it from working in a bare repo. * reinject --known: Fix bug that prevented it from working in a bare repo.
* Support being used in a git repository that uses sha256 rather than sha1. * Support being used in a git repository that uses sha256 rather than sha1.
* initremote, enableremote: Be stricter about rejecting invalid * initremote, enableremote: Be stricter about rejecting invalid
configurations for remotes, particularly things like foo=true when configuration parameters for remotes, particularly things like foo=true
foo=yes is expected when foo=yes is expected.
* initremote, enableremote: Reject unknown parameters provided to these * initremote, enableremote: Reject unknown configuration parameters
commands. provided to these commands.
* initremote: Added --describe-other-params option, to show additional
configuration parameters you might want to set.
* Added LISTCONFIGS to external special remote protocol. Special remote * Added LISTCONFIGS to external special remote protocol. Special remote
programs that use GETCONFIG/SETCONFIG are recommended to implement it. programs that use GETCONFIG/SETCONFIG are recommended to implement it.

View file

@ -96,8 +96,8 @@ paramItem :: String
paramItem = "ITEM" paramItem = "ITEM"
paramTreeish :: String paramTreeish :: String
paramTreeish = "TREEISH" paramTreeish = "TREEISH"
paramKeyValue :: String paramParamValue :: String
paramKeyValue = "K=V" paramParamValue = "PARAM=VALUE"
paramNothing :: String paramNothing :: String
paramNothing = "" paramNothing = ""
paramRepeating :: String -> String paramRepeating :: String -> String

View file

@ -31,7 +31,7 @@ import qualified Data.Map as M
cmd :: Command cmd :: Command
cmd = command "enableremote" SectionSetup cmd = command "enableremote" SectionSetup
"enables git-annex to use a remote" "enables git-annex to use a remote"
(paramPair paramName $ paramOptional $ paramRepeating paramKeyValue) (paramPair paramName $ paramOptional $ paramRepeating paramParamValue)
(withParams seek) (withParams seek)
seek :: CmdParams -> CommandSeek seek :: CmdParams -> CommandSeek

View file

@ -16,6 +16,7 @@ import Annex.SpecialRemote
import qualified Remote import qualified Remote
import qualified Logs.Remote import qualified Logs.Remote
import qualified Types.Remote as R import qualified Types.Remote as R
import Types.RemoteConfig
import Annex.UUID import Annex.UUID
import Logs.UUID import Logs.UUID
import Logs.Remote import Logs.Remote
@ -26,18 +27,24 @@ import Config
cmd :: Command cmd :: Command
cmd = command "initremote" SectionSetup cmd = command "initremote" SectionSetup
"creates a special (non-git) remote" "creates a special (non-git) remote"
(paramPair paramName $ paramOptional $ paramRepeating paramKeyValue) (paramPair paramName $ paramOptional $ paramRepeating paramParamValue)
(seek <$$> optParser) (seek <$$> optParser)
data InitRemoteOptions = InitRemoteOptions data InitRemoteOptions = InitRemoteOptions
{ cmdparams :: CmdParams { cmdparams :: CmdParams
, sameas :: Maybe (DeferredParse UUID) , sameas :: Maybe (DeferredParse UUID)
, describeOtherParams :: Bool
} }
optParser :: CmdParamsDesc -> Parser InitRemoteOptions optParser :: CmdParamsDesc -> Parser InitRemoteOptions
optParser desc = InitRemoteOptions optParser desc = InitRemoteOptions
<$> cmdParams desc <$> cmdParams desc
<*> optional parseSameasOption <*> optional parseSameasOption
<*> switch
( long "describe-other-params"
<> short 'p'
<> help "describe other configuration parameters for a special remote"
)
parseSameasOption :: Parser (DeferredParse UUID) parseSameasOption :: Parser (DeferredParse UUID)
parseSameasOption = parseUUIDOption <$> strOption parseSameasOption = parseUUIDOption <$> strOption
@ -67,8 +74,11 @@ start o (name:ws) = ifM (isJust <$> findExisting name)
(Logs.Remote.keyValToConfig Proposed ws) (Logs.Remote.keyValToConfig Proposed ws)
<$> readRemoteLog <$> readRemoteLog
t <- either giveup return (findType c) t <- either giveup return (findType c)
starting "initremote" (ActionItemOther (Just name)) $ if describeOtherParams o
perform t name c o then startingCustomOutput (ActionItemOther Nothing) $
describeOtherParamsFor c t
else starting "initremote" (ActionItemOther (Just name)) $
perform t name c o
) )
) )
@ -100,3 +110,26 @@ cleanup u name c o = do
setConfig (remoteConfig c "config-uuid") (fromUUID cu) setConfig (remoteConfig c "config-uuid") (fromUUID cu)
Logs.Remote.configSet cu c Logs.Remote.configSet cu c
return True return True
describeOtherParamsFor :: RemoteConfig -> RemoteType -> CommandPerform
describeOtherParamsFor c t = do
cp <- R.configParser t c
let l = mapMaybe mk $ filter notinconfig $ remoteConfigFieldParsers cp
liftIO $ forM_ l $ \(p, pd, vd) -> do
putStrLn p
putStrLn ("\t" ++ pd)
case vd of
Nothing -> return ()
Just vd' -> putStrLn $ "\t(" ++ vd' ++ ")"
next $ return True
where
notinconfig fp = not (M.member (parserForField fp) c)
mk fp = case fieldDesc fp of
HiddenField -> Nothing
FieldDesc d -> Just
( fromProposedAccepted (parserForField fp)
, d
, case valueDesc fp of
Nothing -> Nothing
Just (ValueDesc vd) -> Just vd
)

View file

@ -20,15 +20,12 @@ For a list and details, see <https://git-annex.branchable.com/special_remotes/>
The remote's configuration is specified by the parameters passed The remote's configuration is specified by the parameters passed
to this command. Different types of special remotes need different to this command. Different types of special remotes need different
configuration values, so consult the documentation of a special remote for configuration values, so consult the documentation of a special remote for
details. The command will prompt for any required parameters you leave out. details. The command will prompt for any required parameters you leave out;
you can also pass --describe-other-params to see additional parameters.
A few parameters that are supported by all special remotes are documented in A few parameters that are supported by all special remotes are documented in
the next section below. the next section below.
To list all the configuration parameters that are accepted by a particular
type of special remote, along with short descriptions, run eg:
git annex initremote --list-params-for=S3
Once a special remote has been initialized once with this command, Once a special remote has been initialized once with this command,
other clones of the repository can also be set up to access it using other clones of the repository can also be set up to access it using
`git annex enableremote`. `git annex enableremote`.
@ -41,10 +38,14 @@ want to use `git annex renameremote`.
# OPTIONS # OPTIONS
* `--list-params-for=type` * `--describe-other-params` / `-p`
Lists all configuration parameters that are accepted for a given Describe additional configuration parameters that you could specify.
type of special remote.
For example, if you know you want a S3 remote, but forget how to
configure it:
git annex initremote mys3 type=S3 --describe-other-params
* `--fast` * `--fast`
@ -87,6 +88,7 @@ want to use `git annex renameremote`.
For details about this and other encrpytion settings, see For details about this and other encrpytion settings, see
<https://git-annex.branchable.com/encryption/> <https://git-annex.branchable.com/encryption/>
or --describe-other-params
* `autoenable` * `autoenable`