refactor FromToHereOptions
This commit is contained in:
parent
448c40180b
commit
0106752db2
2 changed files with 24 additions and 12 deletions
|
@ -5,6 +5,8 @@
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
|
||||||
|
|
||||||
module CmdLine.GitAnnex.Options where
|
module CmdLine.GitAnnex.Options where
|
||||||
|
|
||||||
import Options.Applicative
|
import Options.Applicative
|
||||||
|
@ -113,6 +115,7 @@ parseRemoteOption = DeferredParse
|
||||||
. (fromJust <$$> Remote.byNameWithUUID)
|
. (fromJust <$$> Remote.byNameWithUUID)
|
||||||
. Just
|
. Just
|
||||||
|
|
||||||
|
-- | From or To a remote.
|
||||||
data FromToOptions
|
data FromToOptions
|
||||||
= FromRemote (DeferredParse Remote)
|
= FromRemote (DeferredParse Remote)
|
||||||
| ToRemote (DeferredParse Remote)
|
| ToRemote (DeferredParse Remote)
|
||||||
|
@ -140,6 +143,24 @@ parseToOption = strOption
|
||||||
<> completeRemotes
|
<> completeRemotes
|
||||||
)
|
)
|
||||||
|
|
||||||
|
-- | Like FromToOptions, but with a special --to=here
|
||||||
|
type FromToHereOptions = Either ToHere FromToOptions
|
||||||
|
|
||||||
|
data ToHere = ToHere
|
||||||
|
|
||||||
|
parseFromToHereOptions :: Parser FromToHereOptions
|
||||||
|
parseFromToHereOptions = parsefrom <|> parseto
|
||||||
|
where
|
||||||
|
parsefrom = Right . FromRemote . parseRemoteOption <$> parseFromOption
|
||||||
|
parseto = herespecialcase <$> parseToOption
|
||||||
|
where
|
||||||
|
herespecialcase "here" = Left ToHere
|
||||||
|
herespecialcase "." = Left ToHere
|
||||||
|
herespecialcase n = Right $ ToRemote $ parseRemoteOption n
|
||||||
|
|
||||||
|
instance DeferredParseClass FromToHereOptions where
|
||||||
|
finishParse = either (pure . Left) (Right <$$> finishParse)
|
||||||
|
|
||||||
-- Options for acting on keys, rather than work tree files.
|
-- Options for acting on keys, rather than work tree files.
|
||||||
data KeyOptions
|
data KeyOptions
|
||||||
= WantAllKeys
|
= WantAllKeys
|
||||||
|
|
|
@ -27,31 +27,22 @@ cmd = withGlobalOptions [jobsOption, jsonOptions, jsonProgressOption, annexedMat
|
||||||
|
|
||||||
data MoveOptions = MoveOptions
|
data MoveOptions = MoveOptions
|
||||||
{ moveFiles :: CmdParams
|
{ moveFiles :: CmdParams
|
||||||
, fromToOptions :: Either ToHere FromToOptions
|
, fromToOptions :: FromToHereOptions
|
||||||
, keyOptions :: Maybe KeyOptions
|
, keyOptions :: Maybe KeyOptions
|
||||||
, batchOption :: BatchMode
|
, batchOption :: BatchMode
|
||||||
}
|
}
|
||||||
|
|
||||||
data ToHere = ToHere
|
|
||||||
|
|
||||||
optParser :: CmdParamsDesc -> Parser MoveOptions
|
optParser :: CmdParamsDesc -> Parser MoveOptions
|
||||||
optParser desc = MoveOptions
|
optParser desc = MoveOptions
|
||||||
<$> cmdParams desc
|
<$> cmdParams desc
|
||||||
<*> (parsefrom <|> parseto)
|
<*> parseFromToHereOptions
|
||||||
<*> optional (parseKeyOptions <|> parseFailedTransfersOption)
|
<*> optional (parseKeyOptions <|> parseFailedTransfersOption)
|
||||||
<*> parseBatchOption
|
<*> parseBatchOption
|
||||||
where
|
|
||||||
parsefrom = Right . FromRemote . parseRemoteOption <$> parseFromOption
|
|
||||||
parseto = herespecialcase <$> parseToOption
|
|
||||||
where
|
|
||||||
herespecialcase "here" = Left ToHere
|
|
||||||
herespecialcase "." = 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)
|
||||||
<*> either (pure . Left) (Right <$$> finishParse) (fromToOptions v)
|
<*> finishParse (fromToOptions v)
|
||||||
<*> pure (keyOptions v)
|
<*> pure (keyOptions v)
|
||||||
<*> pure (batchOption v)
|
<*> pure (batchOption v)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue