enableremote: List uuids and descriptions of remotes that can be enabled, and accept either the uuid or the description in leu if the name.
This commit is contained in:
parent
016904f424
commit
640dba43b6
7 changed files with 75 additions and 25 deletions
|
@ -42,10 +42,14 @@ findByName n = filter (matching . snd) . M.toList
|
|||
| n' == n -> True
|
||||
| otherwise -> False
|
||||
|
||||
remoteNames :: Annex [RemoteName]
|
||||
remoteNames = do
|
||||
specialRemoteMap :: Annex (M.Map UUID RemoteName)
|
||||
specialRemoteMap = do
|
||||
m <- Logs.Remote.readRemoteLog
|
||||
return $ mapMaybe (M.lookup nameKey . snd) $ M.toList m
|
||||
return $ M.fromList $ mapMaybe go (M.toList m)
|
||||
where
|
||||
go (u, c) = case M.lookup nameKey c of
|
||||
Nothing -> Nothing
|
||||
Just n -> Just (u, n)
|
||||
|
||||
{- find the specified remote type -}
|
||||
findType :: RemoteConfig -> Either String RemoteType
|
||||
|
|
|
@ -12,6 +12,8 @@ import Command
|
|||
import qualified Logs.Remote
|
||||
import qualified Types.Remote as R
|
||||
import qualified Annex.SpecialRemote
|
||||
import qualified Remote
|
||||
import Logs.UUID
|
||||
|
||||
import qualified Data.Map as M
|
||||
|
||||
|
@ -25,12 +27,19 @@ seek :: CmdParams -> CommandSeek
|
|||
seek = withWords start
|
||||
|
||||
start :: [String] -> CommandStart
|
||||
start [] = unknownNameError "Specify the name of the special remote to enable."
|
||||
start [] = unknownNameError "Specify the special remote to enable."
|
||||
start (name:ws) = go =<< Annex.SpecialRemote.findExisting name
|
||||
where
|
||||
config = Logs.Remote.keyValToConfig ws
|
||||
|
||||
go Nothing = unknownNameError "Unknown special remote name."
|
||||
go Nothing = do
|
||||
m <- Annex.SpecialRemote.specialRemoteMap
|
||||
confm <- Logs.Remote.readRemoteLog
|
||||
v <- Remote.nameToUUID' name
|
||||
case v of
|
||||
Right u | u `M.member` m ->
|
||||
go (Just (u, fromMaybe M.empty (M.lookup u confm)))
|
||||
_ -> unknownNameError "Unknown special remote."
|
||||
go (Just (u, c)) = do
|
||||
let fullconfig = config `M.union` c
|
||||
t <- either error return (Annex.SpecialRemote.findType fullconfig)
|
||||
|
@ -39,11 +48,14 @@ start (name:ws) = go =<< Annex.SpecialRemote.findExisting name
|
|||
|
||||
unknownNameError :: String -> Annex a
|
||||
unknownNameError prefix = do
|
||||
names <- Annex.SpecialRemote.remoteNames
|
||||
error $ prefix ++ "\n" ++
|
||||
if null names
|
||||
then "(No special remotes are currently known; perhaps use initremote instead?)"
|
||||
else "Known special remotes: " ++ unwords names
|
||||
m <- Annex.SpecialRemote.specialRemoteMap
|
||||
descm <- M.unionWith Remote.addName <$> uuidMap <*> pure m
|
||||
msg <- if M.null m
|
||||
then pure "(No special remotes are currently known; perhaps use initremote instead?)"
|
||||
else Remote.prettyPrintUUIDsDescs
|
||||
"known special remotes"
|
||||
descm (M.keys m)
|
||||
error $ prefix ++ "\n" ++ msg
|
||||
|
||||
perform :: RemoteType -> UUID -> R.RemoteConfig -> CommandPerform
|
||||
perform t u c = do
|
||||
|
|
|
@ -427,8 +427,9 @@ reposizes_stats = stat desc $ nojson $ do
|
|||
. M.toList
|
||||
<$> cachedRepoData
|
||||
let maxlen = maximum (map (length . snd) l)
|
||||
descm <- lift uuidDescriptions
|
||||
-- This also handles json display.
|
||||
s <- lift $ prettyPrintUUIDsWith (Just "size") desc $
|
||||
s <- lift $ prettyPrintUUIDsWith (Just "size") desc descm $
|
||||
map (\(u, sz) -> (u, Just $ mkdisp sz maxlen)) l
|
||||
return $ countRepoList (length l) s
|
||||
where
|
||||
|
|
33
Remote.hs
33
Remote.hs
|
@ -25,6 +25,7 @@ module Remote (
|
|||
remoteMap,
|
||||
remoteMap',
|
||||
uuidDescriptions,
|
||||
addName,
|
||||
byName,
|
||||
byName',
|
||||
byNameOrGroup,
|
||||
|
@ -32,6 +33,7 @@ module Remote (
|
|||
byNameWithUUID,
|
||||
byCost,
|
||||
prettyPrintUUIDs,
|
||||
prettyPrintUUIDsDescs,
|
||||
prettyPrintUUIDsWith,
|
||||
prettyListUUIDs,
|
||||
prettyUUID,
|
||||
|
@ -168,34 +170,41 @@ nameToUUID' n = byName' n >>= go
|
|||
_ -> Right u
|
||||
_us -> Left "Found multiple repositories with that description"
|
||||
|
||||
{- Pretty-prints a list of UUIDs of remotes, for human display.
|
||||
{- Pretty-prints a list of UUIDs of remotes, with their descriptions,
|
||||
- for human display.
|
||||
-
|
||||
- When JSON is enabled, also outputs a machine-readable description
|
||||
- of the UUIDs. -}
|
||||
prettyPrintUUIDs :: String -> [UUID] -> Annex String
|
||||
prettyPrintUUIDs desc uuids = prettyPrintUUIDsWith Nothing desc $
|
||||
zip uuids (repeat (Nothing :: Maybe String))
|
||||
prettyPrintUUIDs header uuids = do
|
||||
descm <- uuidDescriptions
|
||||
prettyPrintUUIDsDescs header descm uuids
|
||||
|
||||
prettyPrintUUIDsDescs :: String -> M.Map UUID RemoteName -> [UUID] -> Annex String
|
||||
prettyPrintUUIDsDescs header descm uuids =
|
||||
prettyPrintUUIDsWith Nothing header descm
|
||||
(zip uuids (repeat (Nothing :: Maybe String)))
|
||||
|
||||
{- An optional field can be included in the list of UUIDs. -}
|
||||
prettyPrintUUIDsWith
|
||||
:: (JSON v, Show v)
|
||||
=> Maybe String
|
||||
-> String
|
||||
-> M.Map UUID RemoteName
|
||||
-> [(UUID, Maybe v)]
|
||||
-> Annex String
|
||||
prettyPrintUUIDsWith optfield desc uuids = do
|
||||
prettyPrintUUIDsWith optfield header descm uuidvals = do
|
||||
hereu <- getUUID
|
||||
m <- uuidDescriptions
|
||||
maybeShowJSON [(desc, map (jsonify m hereu) uuids)]
|
||||
return $ unwords $ map (\u -> "\t" ++ prettify m hereu u ++ "\n") uuids
|
||||
maybeShowJSON [(header, map (jsonify hereu) uuidvals)]
|
||||
return $ unwords $ map (\u -> "\t" ++ prettify hereu u ++ "\n") uuidvals
|
||||
where
|
||||
finddescription m u = M.findWithDefault "" u m
|
||||
prettify m hereu (u, optval)
|
||||
finddescription u = M.findWithDefault "" u descm
|
||||
prettify hereu (u, optval)
|
||||
| not (null d) = addoptval $ fromUUID u ++ " -- " ++ d
|
||||
| otherwise = addoptval $ fromUUID u
|
||||
where
|
||||
ishere = hereu == u
|
||||
n = finddescription m u
|
||||
n = finddescription u
|
||||
d
|
||||
| null n && ishere = "here"
|
||||
| ishere = addName n "here"
|
||||
|
@ -203,9 +212,9 @@ prettyPrintUUIDsWith optfield desc uuids = do
|
|||
addoptval s = case optval of
|
||||
Nothing -> s
|
||||
Just val -> show val ++ ": " ++ s
|
||||
jsonify m hereu (u, optval) = toJSObject $ catMaybes
|
||||
jsonify hereu (u, optval) = toJSObject $ catMaybes
|
||||
[ Just ("uuid", toJSON $ fromUUID u)
|
||||
, Just ("description", toJSON $ finddescription m u)
|
||||
, Just ("description", toJSON $ finddescription u)
|
||||
, Just ("here", toJSON $ hereu == u)
|
||||
, case (optfield, optval) of
|
||||
(Just field, Just val) -> Just (field, showJSON val)
|
||||
|
|
3
debian/changelog
vendored
3
debian/changelog
vendored
|
@ -3,6 +3,9 @@ git-annex (5.20151020) UNRELEASED; urgency=medium
|
|||
* Use statvfs on OSX.
|
||||
* Symlink timestamp preservation code uses functions
|
||||
from unix-2.7.0 when available, which should be more portable.
|
||||
* enableremote: List uuids and descriptions of remotes that can be
|
||||
enabled, and accept either the uuid or the description in leu if the
|
||||
name.
|
||||
|
||||
-- Joey Hess <id@joeyh.name> Mon, 19 Oct 2015 17:00:21 -0400
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ git-annex enableremote - enables use of an existing special remote
|
|||
|
||||
# SYNOPSIS
|
||||
|
||||
git annex enableremote `name [param=value ...]`
|
||||
git annex enableremote `name|uuid|desc [param=value ...]`
|
||||
|
||||
# DESCRIPTION
|
||||
|
||||
|
@ -15,7 +15,8 @@ originally created with the initremote command.
|
|||
The name of the remote is the same name used when originally
|
||||
creating that remote with `git annex initremote`. Run
|
||||
`git annex enableremote` without any name to get a list of
|
||||
special remote names.
|
||||
special remote names. Or you can specify the uuid or description of the
|
||||
remote.
|
||||
|
||||
Some special remotes may need parameters to be specified every time they are
|
||||
enabled. For example, the directory special remote requires a directory=
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
[[!comment format=mdwn
|
||||
username="joey"
|
||||
subject="""comment 26"""
|
||||
date="2015-10-26T17:36:26Z"
|
||||
content="""
|
||||
@craig, this can be slightly confusing, since `git-annex enableremote`
|
||||
uses the same name that you used when creating the remote in the first
|
||||
place, with `git-annex initremote`... which might be different than
|
||||
the name used for that remote in some repository or other, and from
|
||||
the description shown in `git annex into`.
|
||||
|
||||
Since every remote listed by `git annex info` is apparently a regular git
|
||||
repo, not a special remote, with the exception of the glacier one, process
|
||||
of deduction suggests that the "gitannexpics" special remote is the same as
|
||||
the glacier one.
|
||||
|
||||
I've made some changes now, so `git annex enableremote` will list the
|
||||
uuid and description, along with the name used by enableremote, and
|
||||
will accept any one of those things to specify which remote to enable.
|
||||
"""]]
|
Loading…
Add table
Reference in a new issue