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.
|
||||
-}
|
||||
|
||||
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
|
||||
|
||||
module CmdLine.GitAnnex.Options where
|
||||
|
||||
import Options.Applicative
|
||||
|
@ -113,6 +115,7 @@ parseRemoteOption = DeferredParse
|
|||
. (fromJust <$$> Remote.byNameWithUUID)
|
||||
. Just
|
||||
|
||||
-- | From or To a remote.
|
||||
data FromToOptions
|
||||
= FromRemote (DeferredParse Remote)
|
||||
| ToRemote (DeferredParse Remote)
|
||||
|
@ -140,6 +143,24 @@ parseToOption = strOption
|
|||
<> 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.
|
||||
data KeyOptions
|
||||
= WantAllKeys
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue