more command-specific options

Made --from and --to command-specific options.

Added generic storage for values of command-specific options,
which allows removing some of the special case fields in AnnexState.

(Also added generic storage for command-specific flags, although there are
not yet any.)

Note that this storage uses a Map, so repeatedly looking up the same value
is slightly more expensive than looking up an AnnexState field. But, the
value can be looked up once in the seek stage, transformed as necessary,
and passed in a closure to the start stage, and this avoids that overhead.

Still, I'm hesitant to use this for things like force or fast flags.
It's probably best to reserve it for flags that are only used by a few
commands, or options like --from and --to that it's important only be
allowed to be used with commands that implement them, to avoid user
confusion.
This commit is contained in:
Joey Hess 2012-01-06 03:06:25 -04:00
parent 2051d80462
commit 0a36f92a31
13 changed files with 107 additions and 75 deletions

View file

@ -16,18 +16,25 @@ import qualified Remote
import Annex.UUID
def :: [Command]
def = [dontCheck toOpt $ dontCheck fromOpt $
command "move" paramPaths seek
def = [withOptions options $ command "move" paramPaths seek
"move content of files to/from another repository"]
seek :: [CommandSeek]
seek = [withFilesInGit $ whenAnnexed $ start True]
fromOption :: Option
fromOption = fieldOption ['f'] "from" paramRemote "source remote"
start :: Bool -> FilePath -> (Key, Backend) -> CommandStart
start move file (key, _) = do
toOption :: Option
toOption = fieldOption ['t'] "to" paramRemote "destination remote"
options :: [Option]
options = [fromOption, toOption]
seek :: [CommandSeek]
seek = [withField "to" id $ \to -> withField "from" id $ \from ->
withFilesInGit $ whenAnnexed $ start to from True]
start :: Maybe String -> Maybe String -> Bool -> FilePath -> (Key, Backend) -> CommandStart
start to from move file (key, _) = do
noAuto
to <- Annex.getState Annex.toremote
from <- Annex.getState Annex.fromremote
case (from, to) of
(Nothing, Nothing) -> error "specify either --from or --to"
(Nothing, Just name) -> do