This commit is contained in:
Joey Hess 2015-07-09 16:05:45 -04:00
parent 8ad927dbc6
commit a7f58634b8
11 changed files with 109 additions and 79 deletions

View file

@ -17,29 +17,39 @@ import Annex.Wanted
import qualified Command.Move
cmd :: Command
cmd = withOptions getOptions $
command "get" SectionCommon
"make content of annexed files available"
paramPaths (withParams seek)
cmd = command "get" SectionCommon
"make content of annexed files available"
paramPaths (seek <$$> optParser)
getOptions :: [Option]
getOptions = fromOption : autoOption : jobsOption : annexedMatchingOptions
++ incompleteOption : keyOptions
data GetOptions = GetOptions
{ getFiles :: CmdParams
, getFrom :: Maybe (DeferredParse Remote)
, autoMode :: Bool
, keyOptions :: Maybe KeyOptions
}
seek :: CmdParams -> CommandSeek
seek ps = do
from <- getOptionField fromOption Remote.byNameWithUUID
auto <- getOptionFlag autoOption
withKeyOptions auto
optParser :: CmdParamsDesc -> Parser GetOptions
optParser desc = GetOptions
<$> cmdParams desc
<*> optional parseFromOption
<*> parseAutoOption
<*> optional (parseKeyOptions True)
-- TODO: jobsOption, annexedMatchingOptions
seek :: GetOptions -> CommandSeek
seek o = do
from <- maybe (pure Nothing) (Just <$$> getParsed) (getFrom o)
withKeyOptions (keyOptions o) (autoMode o)
(startKeys from)
(withFilesInGit $ whenAnnexed $ start auto from)
ps
(withFilesInGit $ whenAnnexed $ start o from)
(getFiles o)
start :: Bool -> Maybe Remote -> FilePath -> Key -> CommandStart
start auto from file key = start' expensivecheck from key (Just file)
start :: GetOptions -> Maybe Remote -> FilePath -> Key -> CommandStart
start o from file key = start' expensivecheck from key (Just file)
where
expensivecheck
| auto = numCopiesCheck file key (<) <||> wantGet False (Just key) (Just file)
| autoMode o = numCopiesCheck file key (<) <||> wantGet False (Just key) (Just file)
| otherwise = return True
startKeys :: Maybe Remote -> Key -> CommandStart