convert Import
This commit is contained in:
parent
9c1a42873c
commit
084f8d9ac7
2 changed files with 35 additions and 38 deletions
|
@ -87,7 +87,7 @@ import qualified Command.AddUrl
|
||||||
import qualified Command.ImportFeed
|
import qualified Command.ImportFeed
|
||||||
#endif
|
#endif
|
||||||
import qualified Command.RmUrl
|
import qualified Command.RmUrl
|
||||||
--import qualified Command.Import
|
import qualified Command.Import
|
||||||
import qualified Command.Map
|
import qualified Command.Map
|
||||||
import qualified Command.Direct
|
import qualified Command.Direct
|
||||||
import qualified Command.Indirect
|
import qualified Command.Indirect
|
||||||
|
@ -136,7 +136,7 @@ cmds =
|
||||||
, Command.ImportFeed.cmd
|
, Command.ImportFeed.cmd
|
||||||
#endif
|
#endif
|
||||||
, Command.RmUrl.cmd
|
, Command.RmUrl.cmd
|
||||||
-- , Command.Import.cmd
|
, Command.Import.cmd
|
||||||
, Command.Init.cmd
|
, Command.Init.cmd
|
||||||
, Command.Describe.cmd
|
, Command.Describe.cmd
|
||||||
, Command.InitRemote.cmd
|
, Command.InitRemote.cmd
|
||||||
|
|
|
@ -23,53 +23,50 @@ import Types.TrustLevel
|
||||||
import Logs.Trust
|
import Logs.Trust
|
||||||
|
|
||||||
cmd :: Command
|
cmd :: Command
|
||||||
cmd = withOptions opts $ notBareRepo $
|
cmd = withGlobalOptions fileMatchingOptions $ notBareRepo $
|
||||||
command "import" SectionCommon
|
command "import" SectionCommon
|
||||||
"move and add files from outside git working copy"
|
"move and add files from outside git working copy"
|
||||||
paramPaths (withParams seek)
|
paramPaths (seek <$$> optParser)
|
||||||
|
|
||||||
opts :: [GlobalOption]
|
|
||||||
opts = duplicateModeOptions ++ fileMatchingOptions
|
|
||||||
|
|
||||||
data DuplicateMode = Default | Duplicate | DeDuplicate | CleanDuplicates | SkipDuplicates
|
data DuplicateMode = Default | Duplicate | DeDuplicate | CleanDuplicates | SkipDuplicates
|
||||||
deriving (Eq, Enum, Bounded)
|
deriving (Eq)
|
||||||
|
|
||||||
associatedOption :: DuplicateMode -> Maybe Option
|
data ImportOptions = ImportOptions
|
||||||
associatedOption Default = Nothing
|
{ importFiles :: CmdParams
|
||||||
associatedOption Duplicate = Just $
|
, duplicateMode :: DuplicateMode
|
||||||
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"
|
|
||||||
|
|
||||||
duplicateModeOptions :: [Option]
|
optParser :: CmdParamsDesc -> Parser ImportOptions
|
||||||
duplicateModeOptions = mapMaybe associatedOption [minBound..maxBound]
|
optParser desc = ImportOptions
|
||||||
|
<$> cmdParams desc
|
||||||
|
<*> (fromMaybe Default <$> optional duplicateModeParser)
|
||||||
|
|
||||||
getDuplicateMode :: Annex DuplicateMode
|
duplicateModeParser :: Parser DuplicateMode
|
||||||
getDuplicateMode = go . catMaybes <$> mapM getflag [minBound..maxBound]
|
duplicateModeParser =
|
||||||
where
|
flag' Duplicate
|
||||||
getflag m = case associatedOption m of
|
( long "duplicate"
|
||||||
Nothing -> return Nothing
|
<> help "do not delete source files"
|
||||||
Just o -> ifM (Annex.getFlag (optionName o))
|
)
|
||||||
( return (Just m)
|
<|> flag' DeDuplicate
|
||||||
, return Nothing
|
( long "deduplicate"
|
||||||
)
|
<> help "delete source files whose content was imported before"
|
||||||
go [] = Default
|
)
|
||||||
go [m] = m
|
<|> flag' CleanDuplicates
|
||||||
go ms = error $ "cannot combine " ++
|
( long "clean-duplicates"
|
||||||
unwords (map (optionParam . fromJust . associatedOption) ms)
|
<> help "delete duplicate source files (import nothing)"
|
||||||
|
)
|
||||||
|
<|> flag' SkipDuplicates
|
||||||
|
( long "skip-duplicates"
|
||||||
|
<> help "import only new files"
|
||||||
|
)
|
||||||
|
|
||||||
seek :: CmdParams -> CommandSeek
|
seek :: ImportOptions -> CommandSeek
|
||||||
seek ps = do
|
seek o = do
|
||||||
mode <- getDuplicateMode
|
|
||||||
repopath <- liftIO . absPath =<< fromRepo Git.repoPath
|
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
|
unless (null inrepops) $ do
|
||||||
error $ "cannot import files from inside the working tree (use git annex add instead): " ++ unwords inrepops
|
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 :: DuplicateMode -> (FilePath, FilePath) -> CommandStart
|
||||||
start mode (srcfile, destfile) =
|
start mode (srcfile, destfile) =
|
||||||
|
|
Loading…
Add table
Reference in a new issue