diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-07-13 11:15:21 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-07-13 11:15:21 -0400 |
commit | 93d62419262ca6ec924babe734780f7753d887a4 (patch) | |
tree | f7a3712c088d7bda407b6eba3db75fa76f3dbc3f | |
parent | 32eae8c1b1a88cd21f67290a0d7e337bf467adfb (diff) |
convert Import
-rw-r--r-- | CmdLine/GitAnnex.hs | 4 | ||||
-rw-r--r-- | Command/Import.hs | 69 |
2 files changed, 35 insertions, 38 deletions
diff --git a/CmdLine/GitAnnex.hs b/CmdLine/GitAnnex.hs index 21e780398..ede943804 100644 --- a/CmdLine/GitAnnex.hs +++ b/CmdLine/GitAnnex.hs @@ -87,7 +87,7 @@ import qualified Command.AddUrl import qualified Command.ImportFeed #endif import qualified Command.RmUrl ---import qualified Command.Import +import qualified Command.Import import qualified Command.Map import qualified Command.Direct import qualified Command.Indirect @@ -136,7 +136,7 @@ cmds = , Command.ImportFeed.cmd #endif , Command.RmUrl.cmd --- , Command.Import.cmd + , Command.Import.cmd , Command.Init.cmd , Command.Describe.cmd , Command.InitRemote.cmd diff --git a/Command/Import.hs b/Command/Import.hs index 684641ea3..e84618173 100644 --- a/Command/Import.hs +++ b/Command/Import.hs @@ -23,53 +23,50 @@ import Types.TrustLevel import Logs.Trust cmd :: Command -cmd = withOptions opts $ notBareRepo $ +cmd = withGlobalOptions fileMatchingOptions $ notBareRepo $ command "import" SectionCommon "move and add files from outside git working copy" - paramPaths (withParams seek) - -opts :: [GlobalOption] -opts = duplicateModeOptions ++ fileMatchingOptions + paramPaths (seek <$$> optParser) data DuplicateMode = Default | Duplicate | DeDuplicate | CleanDuplicates | SkipDuplicates - deriving (Eq, Enum, Bounded) + deriving (Eq) -associatedOption :: DuplicateMode -> Maybe Option -associatedOption Default = Nothing -associatedOption Duplicate = Just $ - flagOption [] "duplicate" "do not delete source files" -associatedOption DeDuplicate = Just $ - flagOption [] "deduplicate" "delete source files whose content was imported before" -associatedOption CleanDuplicates = Just $ - flagOption [] "clean-duplicates" "delete duplicate source files (import nothing)" -associatedOption SkipDuplicates = Just $ - flagOption [] "skip-duplicates" "import only new files" +data ImportOptions = ImportOptions + { importFiles :: CmdParams + , duplicateMode :: DuplicateMode + } -duplicateModeOptions :: [Option] -duplicateModeOptions = mapMaybe associatedOption [minBound..maxBound] +optParser :: CmdParamsDesc -> Parser ImportOptions +optParser desc = ImportOptions + <$> cmdParams desc + <*> (fromMaybe Default <$> optional duplicateModeParser) -getDuplicateMode :: Annex DuplicateMode -getDuplicateMode = go . catMaybes <$> mapM getflag [minBound..maxBound] - where - getflag m = case associatedOption m of - Nothing -> return Nothing - Just o -> ifM (Annex.getFlag (optionName o)) - ( return (Just m) - , return Nothing - ) - go [] = Default - go [m] = m - go ms = error $ "cannot combine " ++ - unwords (map (optionParam . fromJust . associatedOption) ms) +duplicateModeParser :: Parser DuplicateMode +duplicateModeParser = + flag' Duplicate + ( long "duplicate" + <> help "do not delete source files" + ) + <|> flag' DeDuplicate + ( long "deduplicate" + <> help "delete source files whose content was imported before" + ) + <|> flag' CleanDuplicates + ( long "clean-duplicates" + <> help "delete duplicate source files (import nothing)" + ) + <|> flag' SkipDuplicates + ( long "skip-duplicates" + <> help "import only new files" + ) -seek :: CmdParams -> CommandSeek -seek ps = do - mode <- getDuplicateMode +seek :: ImportOptions -> CommandSeek +seek o = do repopath <- liftIO . absPath =<< fromRepo Git.repoPath - inrepops <- liftIO $ filter (dirContains repopath) <$> mapM absPath ps + inrepops <- liftIO $ filter (dirContains repopath) <$> mapM absPath (importFiles o) unless (null inrepops) $ do error $ "cannot import files from inside the working tree (use git annex add instead): " ++ unwords inrepops - withPathContents (start mode) ps + withPathContents (start (duplicateMode o)) (importFiles o) start :: DuplicateMode -> (FilePath, FilePath) -> CommandStart start mode (srcfile, destfile) = |