refactor FromToHereOptions

This commit is contained in:
Joey Hess 2018-04-09 14:29:28 -04:00
parent 448c40180b
commit 0106752db2
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 24 additions and 12 deletions

View file

@ -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