incomplete multiple --from / --to support

Note that --from foo --to bar is still not allowed by the option parser.
The goal of this change is only to support the same action over a group
of remotes, not multiple different actions. For the same reason
--to here --to foo is not allowed, since that's really two different
actions.

Each file is processed for all listed remotes in turn, so this is not
the same as two git-annex commands run in sequence. Instead, it allows
concurrent actions to several remotes.

Only move and transferkey converted so far. The code in Command.Move is
ugly and needs to be refactored and generalized.
Build fails due to unconverted modules.

This commit was sponsored by Fernando Jimenez on Patreon.
This commit is contained in:
Joey Hess 2018-10-01 15:40:12 -04:00
parent 53526136e8
commit 31ed034f69
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
6 changed files with 65 additions and 45 deletions

View file

@ -119,18 +119,16 @@ parseRemoteOption = DeferredParse
. Just
-- | From or To a remote.
data FromToOptions
= FromRemote (DeferredParse Remote)
| ToRemote (DeferredParse Remote)
data FromToOptions r = From r | To r
instance DeferredParseClass FromToOptions where
finishParse (FromRemote v) = FromRemote <$> finishParse v
finishParse (ToRemote v) = ToRemote <$> finishParse v
instance DeferredParseClass (FromToOptions [DeferredParse r]) where
finishParse (From l) = From <$> finishParse l
finishParse (To l) = To <$> finishParse l
parseFromToOptions :: Parser FromToOptions
parseFromToOptions :: Parser (FromToOptions [DeferredParse Remote])
parseFromToOptions =
(FromRemote . parseRemoteOption <$> parseFromOption)
<|> (ToRemote . parseRemoteOption <$> parseToOption)
(From . map parseRemoteOption <$> some parseFromOption)
<|> (To . map parseRemoteOption <$> some parseToOption)
parseFromOption :: Parser RemoteName
parseFromOption = strOption
@ -147,21 +145,25 @@ parseToOption = strOption
)
-- | Like FromToOptions, but with a special --to=here
type FromToHereOptions = Either ToHere FromToOptions
type FromToHereOptions r = Either ToHere (FromToOptions r)
data ToHere = ToHere
parseFromToHereOptions :: Parser FromToHereOptions
parseFromToHereOptions :: Parser (FromToHereOptions [DeferredParse Remote])
parseFromToHereOptions = parsefrom <|> parseto
where
parsefrom = Right . FromRemote . parseRemoteOption <$> parseFromOption
parseto = herespecialcase <$> parseToOption
parsefrom = Right . From . map parseRemoteOption <$> some parseFromOption
parseto = herespecialcase <$> some parseToOption
where
herespecialcase "here" = Left ToHere
herespecialcase "." = Left ToHere
herespecialcase n = Right $ ToRemote $ parseRemoteOption n
herespecialcase l
| any ishere l && all ishere l = Left ToHere
| any ishere l = fail "Cannot mix --to=here with --to=remote"
| otherwise = Right $ To $ map parseRemoteOption l
ishere "here" = True
ishere "." = True
ishere _ = False
instance DeferredParseClass FromToHereOptions where
instance DeferredParseClass (FromToHereOptions [DeferredParse r]) where
finishParse = either (pure . Left) (Right <$$> finishParse)
-- Options for acting on keys, rather than work tree files.