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
|
| n' == n -> True
|
||||||
| otherwise -> False
|
| otherwise -> False
|
||||||
|
|
||||||
remoteNames :: Annex [RemoteName]
|
specialRemoteMap :: Annex (M.Map UUID RemoteName)
|
||||||
remoteNames = do
|
specialRemoteMap = do
|
||||||
m <- Logs.Remote.readRemoteLog
|
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 -}
|
{- find the specified remote type -}
|
||||||
findType :: RemoteConfig -> Either String RemoteType
|
findType :: RemoteConfig -> Either String RemoteType
|
||||||
|
|
|
@ -12,6 +12,8 @@ import Command
|
||||||
import qualified Logs.Remote
|
import qualified Logs.Remote
|
||||||
import qualified Types.Remote as R
|
import qualified Types.Remote as R
|
||||||
import qualified Annex.SpecialRemote
|
import qualified Annex.SpecialRemote
|
||||||
|
import qualified Remote
|
||||||
|
import Logs.UUID
|
||||||
|
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
|
|
||||||
|
@ -25,12 +27,19 @@ seek :: CmdParams -> CommandSeek
|
||||||
seek = withWords start
|
seek = withWords start
|
||||||
|
|
||||||
start :: [String] -> CommandStart
|
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
|
start (name:ws) = go =<< Annex.SpecialRemote.findExisting name
|
||||||
where
|
where
|
||||||
config = Logs.Remote.keyValToConfig ws
|
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
|
go (Just (u, c)) = do
|
||||||
let fullconfig = config `M.union` c
|
let fullconfig = config `M.union` c
|
||||||
t <- either error return (Annex.SpecialRemote.findType fullconfig)
|
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 :: String -> Annex a
|
||||||
unknownNameError prefix = do
|
unknownNameError prefix = do
|
||||||
names <- Annex.SpecialRemote.remoteNames
|
m <- Annex.SpecialRemote.specialRemoteMap
|
||||||
error $ prefix ++ "\n" ++
|
descm <- M.unionWith Remote.addName <$> uuidMap <*> pure m
|
||||||
if null names
|
msg <- if M.null m
|
||||||
then "(No special remotes are currently known; perhaps use initremote instead?)"
|
then pure "(No special remotes are currently known; perhaps use initremote instead?)"
|
||||||
else "Known special remotes: " ++ unwords names
|
else Remote.prettyPrintUUIDsDescs
|
||||||
|
"known special remotes"
|
||||||
|
descm (M.keys m)
|
||||||
|
error $ prefix ++ "\n" ++ msg
|
||||||
|
|
||||||
perform :: RemoteType -> UUID -> R.RemoteConfig -> CommandPerform
|
perform :: RemoteType -> UUID -> R.RemoteConfig -> CommandPerform
|
||||||
perform t u c = do
|
perform t u c = do
|
||||||
|
|
|
@ -427,8 +427,9 @@ reposizes_stats = stat desc $ nojson $ do
|
||||||
. M.toList
|
. M.toList
|
||||||
<$> cachedRepoData
|
<$> cachedRepoData
|
||||||
let maxlen = maximum (map (length . snd) l)
|
let maxlen = maximum (map (length . snd) l)
|
||||||
|
descm <- lift uuidDescriptions
|
||||||
-- This also handles json display.
|
-- 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
|
map (\(u, sz) -> (u, Just $ mkdisp sz maxlen)) l
|
||||||
return $ countRepoList (length l) s
|
return $ countRepoList (length l) s
|
||||||
where
|
where
|
||||||
|
|
33
Remote.hs
33
Remote.hs
|
@ -25,6 +25,7 @@ module Remote (
|
||||||
remoteMap,
|
remoteMap,
|
||||||
remoteMap',
|
remoteMap',
|
||||||
uuidDescriptions,
|
uuidDescriptions,
|
||||||
|
addName,
|
||||||
byName,
|
byName,
|
||||||
byName',
|
byName',
|
||||||
byNameOrGroup,
|
byNameOrGroup,
|
||||||
|
@ -32,6 +33,7 @@ module Remote (
|
||||||
byNameWithUUID,
|
byNameWithUUID,
|
||||||
byCost,
|
byCost,
|
||||||
prettyPrintUUIDs,
|
prettyPrintUUIDs,
|
||||||
|
prettyPrintUUIDsDescs,
|
||||||
prettyPrintUUIDsWith,
|
prettyPrintUUIDsWith,
|
||||||
prettyListUUIDs,
|
prettyListUUIDs,
|
||||||
prettyUUID,
|
prettyUUID,
|
||||||
|
@ -168,34 +170,41 @@ nameToUUID' n = byName' n >>= go
|
||||||
_ -> Right u
|
_ -> Right u
|
||||||
_us -> Left "Found multiple repositories with that description"
|
_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
|
- When JSON is enabled, also outputs a machine-readable description
|
||||||
- of the UUIDs. -}
|
- of the UUIDs. -}
|
||||||
prettyPrintUUIDs :: String -> [UUID] -> Annex String
|
prettyPrintUUIDs :: String -> [UUID] -> Annex String
|
||||||
prettyPrintUUIDs desc uuids = prettyPrintUUIDsWith Nothing desc $
|
prettyPrintUUIDs header uuids = do
|
||||||
zip uuids (repeat (Nothing :: Maybe String))
|
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. -}
|
{- An optional field can be included in the list of UUIDs. -}
|
||||||
prettyPrintUUIDsWith
|
prettyPrintUUIDsWith
|
||||||
:: (JSON v, Show v)
|
:: (JSON v, Show v)
|
||||||
=> Maybe String
|
=> Maybe String
|
||||||
-> String
|
-> String
|
||||||
|
-> M.Map UUID RemoteName
|
||||||
-> [(UUID, Maybe v)]
|
-> [(UUID, Maybe v)]
|
||||||
-> Annex String
|
-> Annex String
|
||||||
prettyPrintUUIDsWith optfield desc uuids = do
|
prettyPrintUUIDsWith optfield header descm uuidvals = do
|
||||||
hereu <- getUUID
|
hereu <- getUUID
|
||||||
m <- uuidDescriptions
|
maybeShowJSON [(header, map (jsonify hereu) uuidvals)]
|
||||||
maybeShowJSON [(desc, map (jsonify m hereu) uuids)]
|
return $ unwords $ map (\u -> "\t" ++ prettify hereu u ++ "\n") uuidvals
|
||||||
return $ unwords $ map (\u -> "\t" ++ prettify m hereu u ++ "\n") uuids
|
|
||||||
where
|
where
|
||||||
finddescription m u = M.findWithDefault "" u m
|
finddescription u = M.findWithDefault "" u descm
|
||||||
prettify m hereu (u, optval)
|
prettify hereu (u, optval)
|
||||||
| not (null d) = addoptval $ fromUUID u ++ " -- " ++ d
|
| not (null d) = addoptval $ fromUUID u ++ " -- " ++ d
|
||||||
| otherwise = addoptval $ fromUUID u
|
| otherwise = addoptval $ fromUUID u
|
||||||
where
|
where
|
||||||
ishere = hereu == u
|
ishere = hereu == u
|
||||||
n = finddescription m u
|
n = finddescription u
|
||||||
d
|
d
|
||||||
| null n && ishere = "here"
|
| null n && ishere = "here"
|
||||||
| ishere = addName n "here"
|
| ishere = addName n "here"
|
||||||
|
@ -203,9 +212,9 @@ prettyPrintUUIDsWith optfield desc uuids = do
|
||||||
addoptval s = case optval of
|
addoptval s = case optval of
|
||||||
Nothing -> s
|
Nothing -> s
|
||||||
Just val -> show val ++ ": " ++ 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 ("uuid", toJSON $ fromUUID u)
|
||||||
, Just ("description", toJSON $ finddescription m u)
|
, Just ("description", toJSON $ finddescription u)
|
||||||
, Just ("here", toJSON $ hereu == u)
|
, Just ("here", toJSON $ hereu == u)
|
||||||
, case (optfield, optval) of
|
, case (optfield, optval) of
|
||||||
(Just field, Just val) -> Just (field, showJSON val)
|
(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.
|
* Use statvfs on OSX.
|
||||||
* Symlink timestamp preservation code uses functions
|
* Symlink timestamp preservation code uses functions
|
||||||
from unix-2.7.0 when available, which should be more portable.
|
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
|
-- 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
|
# SYNOPSIS
|
||||||
|
|
||||||
git annex enableremote `name [param=value ...]`
|
git annex enableremote `name|uuid|desc [param=value ...]`
|
||||||
|
|
||||||
# DESCRIPTION
|
# DESCRIPTION
|
||||||
|
|
||||||
|
@ -15,7 +15,8 @@ originally created with the initremote command.
|
||||||
The name of the remote is the same name used when originally
|
The name of the remote is the same name used when originally
|
||||||
creating that remote with `git annex initremote`. Run
|
creating that remote with `git annex initremote`. Run
|
||||||
`git annex enableremote` without any name to get a list of
|
`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
|
Some special remotes may need parameters to be specified every time they are
|
||||||
enabled. For example, the directory special remote requires a directory=
|
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