support parsing options like --to=here
Reworked remote name parsing to allow things like that. Command.Move uses it for --to=here, although there's not yet an implementation of that option. This commit was sponsored by Ignacio on Patreon.
This commit is contained in:
parent
df880fe815
commit
5ee6912cf3
6 changed files with 32 additions and 22 deletions
|
@ -1,6 +1,6 @@
|
||||||
{- git-annex command-line option parsing
|
{- git-annex command-line option parsing
|
||||||
-
|
-
|
||||||
- Copyright 2010-2015 Joey Hess <id@joeyh.name>
|
- Copyright 2010-2017 Joey Hess <id@joeyh.name>
|
||||||
-
|
-
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
@ -105,10 +105,10 @@ parseAutoOption = switch
|
||||||
<> help "automatic mode"
|
<> help "automatic mode"
|
||||||
)
|
)
|
||||||
|
|
||||||
parseRemoteOption :: Parser RemoteName -> Parser (DeferredParse Remote)
|
parseRemoteOption :: RemoteName -> DeferredParse Remote
|
||||||
parseRemoteOption p = DeferredParse
|
parseRemoteOption = DeferredParse
|
||||||
. (fromJust <$$> Remote.byNameWithUUID)
|
. (fromJust <$$> Remote.byNameWithUUID)
|
||||||
. Just <$> p
|
. Just
|
||||||
|
|
||||||
data FromToOptions
|
data FromToOptions
|
||||||
= FromRemote (DeferredParse Remote)
|
= FromRemote (DeferredParse Remote)
|
||||||
|
@ -120,18 +120,18 @@ instance DeferredParseClass FromToOptions where
|
||||||
|
|
||||||
parseFromToOptions :: Parser FromToOptions
|
parseFromToOptions :: Parser FromToOptions
|
||||||
parseFromToOptions =
|
parseFromToOptions =
|
||||||
(FromRemote <$> parseFromOption)
|
(FromRemote . parseRemoteOption <$> parseFromOption)
|
||||||
<|> (ToRemote <$> parseToOption)
|
<|> (ToRemote . parseRemoteOption <$> parseToOption)
|
||||||
|
|
||||||
parseFromOption :: Parser (DeferredParse Remote)
|
parseFromOption :: Parser RemoteName
|
||||||
parseFromOption = parseRemoteOption $ strOption
|
parseFromOption = strOption
|
||||||
( long "from" <> short 'f' <> metavar paramRemote
|
( long "from" <> short 'f' <> metavar paramRemote
|
||||||
<> help "source remote"
|
<> help "source remote"
|
||||||
<> completeRemotes
|
<> completeRemotes
|
||||||
)
|
)
|
||||||
|
|
||||||
parseToOption :: Parser (DeferredParse Remote)
|
parseToOption :: Parser RemoteName
|
||||||
parseToOption = parseRemoteOption $ strOption
|
parseToOption = strOption
|
||||||
( long "to" <> short 't' <> metavar paramRemote
|
( long "to" <> short 't' <> metavar paramRemote
|
||||||
<> help "destination remote"
|
<> help "destination remote"
|
||||||
<> completeRemotes
|
<> completeRemotes
|
||||||
|
|
|
@ -52,7 +52,7 @@ start o file key = stopUnless shouldCopy $
|
||||||
| autoMode o = want <||> numCopiesCheck file key (<)
|
| autoMode o = want <||> numCopiesCheck file key (<)
|
||||||
| otherwise = return True
|
| otherwise = return True
|
||||||
want = case Command.Move.fromToOptions (moveOptions o) of
|
want = case Command.Move.fromToOptions (moveOptions o) of
|
||||||
ToRemote dest -> (Remote.uuid <$> getParsed dest) >>=
|
Right (ToRemote dest) -> (Remote.uuid <$> getParsed dest) >>=
|
||||||
wantSend False (Just key) (AssociatedFile (Just file))
|
wantSend False (Just key) (AssociatedFile (Just file))
|
||||||
FromRemote _ ->
|
Right (FromRemote _) ->
|
||||||
wantGet False (Just key) (AssociatedFile (Just file))
|
wantGet False (Just key) (AssociatedFile (Just file))
|
||||||
|
|
|
@ -45,7 +45,7 @@ optParser desc = DropOptions
|
||||||
<*> parseBatchOption
|
<*> parseBatchOption
|
||||||
|
|
||||||
parseDropFromOption :: Parser (DeferredParse Remote)
|
parseDropFromOption :: Parser (DeferredParse Remote)
|
||||||
parseDropFromOption = parseRemoteOption $ strOption
|
parseDropFromOption = parseRemoteOption <$> strOption
|
||||||
( long "from" <> short 'f' <> metavar paramRemote
|
( long "from" <> short 'f' <> metavar paramRemote
|
||||||
<> help "drop content from a remote"
|
<> help "drop content from a remote"
|
||||||
<> completeRemotes
|
<> completeRemotes
|
||||||
|
|
|
@ -62,7 +62,7 @@ data IncrementalOpt
|
||||||
optParser :: CmdParamsDesc -> Parser FsckOptions
|
optParser :: CmdParamsDesc -> Parser FsckOptions
|
||||||
optParser desc = FsckOptions
|
optParser desc = FsckOptions
|
||||||
<$> cmdParams desc
|
<$> cmdParams desc
|
||||||
<*> optional (parseRemoteOption $ strOption
|
<*> optional (parseRemoteOption <$> strOption
|
||||||
( long "from" <> short 'f' <> metavar paramRemote
|
( long "from" <> short 'f' <> metavar paramRemote
|
||||||
<> help "check remote"
|
<> help "check remote"
|
||||||
<> completeRemotes
|
<> completeRemotes
|
||||||
|
|
|
@ -32,7 +32,7 @@ data GetOptions = GetOptions
|
||||||
optParser :: CmdParamsDesc -> Parser GetOptions
|
optParser :: CmdParamsDesc -> Parser GetOptions
|
||||||
optParser desc = GetOptions
|
optParser desc = GetOptions
|
||||||
<$> cmdParams desc
|
<$> cmdParams desc
|
||||||
<*> optional parseFromOption
|
<*> optional (parseRemoteOption <$> parseFromOption)
|
||||||
<*> parseAutoOption
|
<*> parseAutoOption
|
||||||
<*> optional (parseIncompleteOption <|> parseKeyOptions <|> parseFailedTransfersOption)
|
<*> optional (parseIncompleteOption <|> parseKeyOptions <|> parseFailedTransfersOption)
|
||||||
<*> parseBatchOption
|
<*> parseBatchOption
|
||||||
|
|
|
@ -27,20 +27,28 @@ cmd = withGlobalOptions (jobsOption : jsonOption : jsonProgressOption : annexedM
|
||||||
|
|
||||||
data MoveOptions = MoveOptions
|
data MoveOptions = MoveOptions
|
||||||
{ moveFiles :: CmdParams
|
{ moveFiles :: CmdParams
|
||||||
, fromToOptions :: FromToOptions
|
, fromToOptions :: Either ToHere FromToOptions
|
||||||
, keyOptions :: Maybe KeyOptions
|
, keyOptions :: Maybe KeyOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data ToHere = ToHere
|
||||||
|
|
||||||
optParser :: CmdParamsDesc -> Parser MoveOptions
|
optParser :: CmdParamsDesc -> Parser MoveOptions
|
||||||
optParser desc = MoveOptions
|
optParser desc = MoveOptions
|
||||||
<$> cmdParams desc
|
<$> cmdParams desc
|
||||||
<*> parseFromToOptions
|
<*> (parsefrom <|> parseto)
|
||||||
<*> optional (parseKeyOptions <|> parseFailedTransfersOption)
|
<*> optional (parseKeyOptions <|> parseFailedTransfersOption)
|
||||||
|
where
|
||||||
|
parsefrom = Right . FromRemote . parseRemoteOption <$> parseFromOption
|
||||||
|
parseto = herespecialcase <$> parseToOption
|
||||||
|
where
|
||||||
|
herespecialcase "here" = Left ToHere
|
||||||
|
herespecialcase n = Right $ ToRemote $ parseRemoteOption n
|
||||||
|
|
||||||
instance DeferredParseClass MoveOptions where
|
instance DeferredParseClass MoveOptions where
|
||||||
finishParse v = MoveOptions
|
finishParse v = MoveOptions
|
||||||
<$> pure (moveFiles v)
|
<$> pure (moveFiles v)
|
||||||
<*> finishParse (fromToOptions v)
|
<*> either (pure . Left) (Right <$$> finishParse) (fromToOptions v)
|
||||||
<*> pure (keyOptions v)
|
<*> pure (keyOptions v)
|
||||||
|
|
||||||
seek :: MoveOptions -> CommandSeek
|
seek :: MoveOptions -> CommandSeek
|
||||||
|
@ -61,10 +69,12 @@ startKey o move = start' o move (AssociatedFile Nothing)
|
||||||
start' :: MoveOptions -> Bool -> AssociatedFile -> Key -> ActionItem -> CommandStart
|
start' :: MoveOptions -> Bool -> AssociatedFile -> Key -> ActionItem -> CommandStart
|
||||||
start' o move afile key ai =
|
start' o move afile key ai =
|
||||||
case fromToOptions o of
|
case fromToOptions o of
|
||||||
FromRemote src -> checkFailedTransferDirection ai Download $
|
Right (FromRemote src) ->
|
||||||
fromStart move afile key ai =<< getParsed src
|
checkFailedTransferDirection ai Download $
|
||||||
ToRemote dest -> checkFailedTransferDirection ai Upload $
|
fromStart move afile key ai =<< getParsed src
|
||||||
toStart move afile key ai =<< getParsed dest
|
Right (ToRemote dest) ->
|
||||||
|
checkFailedTransferDirection ai Upload $
|
||||||
|
toStart move afile key ai =<< getParsed dest
|
||||||
|
|
||||||
showMoveAction :: Bool -> Key -> ActionItem -> Annex ()
|
showMoveAction :: Bool -> Key -> ActionItem -> Annex ()
|
||||||
showMoveAction move = showStart' (if move then "move" else "copy")
|
showMoveAction move = showStart' (if move then "move" else "copy")
|
||||||
|
|
Loading…
Reference in a new issue