diff options
author | Joey Hess <joeyh@joeyh.name> | 2017-05-31 16:20:55 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2017-05-31 16:49:28 -0400 |
commit | 75ae06595a6971eb21630928bcdd3f33c06b3ea0 (patch) | |
tree | 9bb64df745731601e451e092235715f22c2e9ad7 /Command/Move.hs | |
parent | c2f804b9b2d80af91bac1d0b074c664efcf8da97 (diff) |
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.
Diffstat (limited to 'Command/Move.hs')
-rw-r--r-- | Command/Move.hs | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/Command/Move.hs b/Command/Move.hs index ca4febe76..787afd929 100644 --- a/Command/Move.hs +++ b/Command/Move.hs @@ -27,20 +27,28 @@ cmd = withGlobalOptions (jobsOption : jsonOption : jsonProgressOption : annexedM data MoveOptions = MoveOptions { moveFiles :: CmdParams - , fromToOptions :: FromToOptions + , fromToOptions :: Either ToHere FromToOptions , keyOptions :: Maybe KeyOptions } +data ToHere = ToHere + optParser :: CmdParamsDesc -> Parser MoveOptions optParser desc = MoveOptions <$> cmdParams desc - <*> parseFromToOptions + <*> (parsefrom <|> parseto) <*> 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 finishParse v = MoveOptions <$> pure (moveFiles v) - <*> finishParse (fromToOptions v) + <*> either (pure . Left) (Right <$$> finishParse) (fromToOptions v) <*> pure (keyOptions v) seek :: MoveOptions -> CommandSeek @@ -61,10 +69,12 @@ startKey o move = start' o move (AssociatedFile Nothing) start' :: MoveOptions -> Bool -> AssociatedFile -> Key -> ActionItem -> CommandStart start' o move afile key ai = case fromToOptions o of - FromRemote src -> checkFailedTransferDirection ai Download $ - fromStart move afile key ai =<< getParsed src - ToRemote dest -> checkFailedTransferDirection ai Upload $ - toStart move afile key ai =<< getParsed dest + Right (FromRemote src) -> + checkFailedTransferDirection ai Download $ + fromStart move afile key ai =<< getParsed src + Right (ToRemote dest) -> + checkFailedTransferDirection ai Upload $ + toStart move afile key ai =<< getParsed dest showMoveAction :: Bool -> Key -> ActionItem -> Annex () showMoveAction move = showStart' (if move then "move" else "copy") |