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:
parent
2051d80462
commit
0a36f92a31
13 changed files with 107 additions and 75 deletions
|
@ -12,15 +12,15 @@ import Command
|
|||
import qualified Command.Move
|
||||
|
||||
def :: [Command]
|
||||
def = [dontCheck toOpt $ dontCheck fromOpt $
|
||||
command "copy" paramPaths seek
|
||||
def = [withOptions Command.Move.options $ command "copy" paramPaths seek
|
||||
"copy content of files to/from another repository"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
seek = [withNumCopies $ \n -> whenAnnexed $ start n]
|
||||
seek = [withField "to" id $ \to -> withField "from" id $ \from ->
|
||||
withNumCopies $ \n -> whenAnnexed $ start to from n]
|
||||
|
||||
-- A copy is just a move that does not delete the source file.
|
||||
-- However, --auto mode avoids unnecessary copies.
|
||||
start :: Maybe Int -> FilePath -> (Key, Backend) -> CommandStart
|
||||
start numcopies file (key, backend) = autoCopies key (<) numcopies $
|
||||
Command.Move.start False file (key, backend)
|
||||
start :: Maybe String -> Maybe String -> Maybe Int -> FilePath -> (Key, Backend) -> CommandStart
|
||||
start to from numcopies file (key, backend) = autoCopies key (<) numcopies $
|
||||
Command.Move.start to from False file (key, backend)
|
||||
|
|
|
@ -18,15 +18,18 @@ import Annex.Content
|
|||
import Config
|
||||
|
||||
def :: [Command]
|
||||
def = [dontCheck fromOpt $ command "drop" paramPaths seek
|
||||
def = [withOptions [fromOption] $ command "drop" paramPaths seek
|
||||
"indicate content of files not currently wanted"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
seek = [withNumCopies $ \n -> whenAnnexed $ start n]
|
||||
fromOption :: Option
|
||||
fromOption = fieldOption ['f'] "from" paramRemote "drop content from a remote"
|
||||
|
||||
start :: Maybe Int -> FilePath -> (Key, Backend) -> CommandStart
|
||||
start numcopies file (key, _) = autoCopies key (>) numcopies $ do
|
||||
from <- Annex.getState Annex.fromremote
|
||||
seek :: [CommandSeek]
|
||||
seek = [withField "from" id $ \from -> withNumCopies $ \n ->
|
||||
whenAnnexed $ start from n]
|
||||
|
||||
start :: Maybe String -> Maybe Int -> FilePath -> (Key, Backend) -> CommandStart
|
||||
start from numcopies file (key, _) = autoCopies key (>) numcopies $ do
|
||||
case from of
|
||||
Nothing -> startLocal file numcopies key
|
||||
Just name -> do
|
||||
|
|
|
@ -20,8 +20,9 @@ import Types.Key
|
|||
type UnusedMap = M.Map String Key
|
||||
|
||||
def :: [Command]
|
||||
def = [dontCheck fromOpt $ command "dropunused" (paramRepeating paramNumber)
|
||||
seek "drop unused file content"]
|
||||
def = [withOptions [Command.Drop.fromOption] $
|
||||
command "dropunused" (paramRepeating paramNumber)
|
||||
seek "drop unused file content"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
seek = [withUnusedMaps]
|
||||
|
@ -50,7 +51,7 @@ start (unused, unusedbad, unusedtmp) s = search
|
|||
next $ a key
|
||||
|
||||
perform :: Key -> CommandPerform
|
||||
perform key = maybe droplocal dropremote =<< Annex.getState Annex.fromremote
|
||||
perform key = maybe droplocal dropremote =<< Annex.getField "from"
|
||||
where
|
||||
dropremote name = do
|
||||
r <- Remote.byName name
|
||||
|
|
|
@ -23,20 +23,25 @@ def = [withOptions [formatOption, print0Option] $
|
|||
command "find" paramPaths seek "lists available files"]
|
||||
|
||||
print0Option :: Option
|
||||
print0Option = Option [] ["print0"] (NoArg $ setFormat "${file}\0")
|
||||
print0Option = Option [] ["print0"] (NoArg $ Annex.setField "format" "${file}\0")
|
||||
"terminate output with null"
|
||||
|
||||
seek :: [CommandSeek]
|
||||
seek = [withFilesInGit $ whenAnnexed start]
|
||||
formatOption :: Option
|
||||
formatOption = fieldOption [] "format" paramFormat "control format of output"
|
||||
|
||||
start :: FilePath -> (Key, Backend) -> CommandStart
|
||||
start file (key, _) = do
|
||||
seek :: [CommandSeek]
|
||||
seek = [withField "format" formatconverter $ \f ->
|
||||
withFilesInGit $ whenAnnexed $ start f]
|
||||
where
|
||||
formatconverter = maybe Nothing (Just . Utility.Format.gen)
|
||||
|
||||
start :: Maybe Utility.Format.Format -> FilePath -> (Key, Backend) -> CommandStart
|
||||
start format file (key, _) = do
|
||||
-- only files inAnnex are shown, unless the user has requested
|
||||
-- others via a limit
|
||||
whenM (liftM2 (||) limited (inAnnex key)) $
|
||||
unlessM (showFullJSON vars) $ do
|
||||
f <- Annex.getState Annex.format
|
||||
case f of
|
||||
unlessM (showFullJSON vars) $
|
||||
case format of
|
||||
Nothing -> liftIO $ putStrLn file
|
||||
Just formatter -> liftIO $ putStr $
|
||||
Utility.Format.format formatter $
|
||||
|
|
|
@ -9,22 +9,21 @@ module Command.Get where
|
|||
|
||||
import Common.Annex
|
||||
import Command
|
||||
import qualified Annex
|
||||
import qualified Remote
|
||||
import Annex.Content
|
||||
import qualified Command.Move
|
||||
|
||||
def :: [Command]
|
||||
def = [dontCheck fromOpt $ command "get" paramPaths seek
|
||||
def = [withOptions [Command.Move.fromOption] $ command "get" paramPaths seek
|
||||
"make content of annexed files available"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
seek = [withNumCopies $ \n -> whenAnnexed $ start n]
|
||||
seek = [withField "from" id $ \from -> withNumCopies $ \n ->
|
||||
whenAnnexed $ start from n]
|
||||
|
||||
start :: Maybe Int -> FilePath -> (Key, Backend) -> CommandStart
|
||||
start numcopies file (key, _) = stopUnless (not <$> inAnnex key) $
|
||||
start :: Maybe String -> Maybe Int -> FilePath -> (Key, Backend) -> CommandStart
|
||||
start from numcopies file (key, _) = stopUnless (not <$> inAnnex key) $
|
||||
autoCopies key (<) numcopies $ do
|
||||
from <- Annex.getState Annex.fromremote
|
||||
case from of
|
||||
Nothing -> go $ perform key
|
||||
Just name -> do
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -30,16 +30,19 @@ import qualified Annex.Branch
|
|||
import Annex.CatFile
|
||||
|
||||
def :: [Command]
|
||||
def = [dontCheck fromOpt $ command "unused" paramNothing seek
|
||||
def = [withOptions [fromOption] $ command "unused" paramNothing seek
|
||||
"look for unused file content"]
|
||||
|
||||
fromOption :: Option
|
||||
fromOption = fieldOption ['f'] "from" paramRemote "remote to check for unused content"
|
||||
|
||||
seek :: [CommandSeek]
|
||||
seek = [withNothing start]
|
||||
seek = [withNothing $ start]
|
||||
|
||||
{- Finds unused content in the annex. -}
|
||||
start :: CommandStart
|
||||
start = do
|
||||
from <- Annex.getState Annex.fromremote
|
||||
from <- Annex.getField "from"
|
||||
let (name, action) = case from of
|
||||
Nothing -> (".", checkUnused)
|
||||
Just "." -> (".", checkUnused)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue