summaryrefslogtreecommitdiff
path: root/Command/Add.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Command/Add.hs')
-rw-r--r--Command/Add.hs39
1 files changed, 23 insertions, 16 deletions
diff --git a/Command/Add.hs b/Command/Add.hs
index 5f6f06cdb..11682207e 100644
--- a/Command/Add.hs
+++ b/Command/Add.hs
@@ -34,28 +34,35 @@ import Utility.Tmp
import Control.Exception (IOException)
-cmd :: [Command]
-cmd = [notBareRepo $ withOptions addOptions $
- command "add" paramPaths seek SectionCommon "add files to annex"]
+cmd :: Command
+cmd = notBareRepo $ withGlobalOptions fileMatchingOptions $
+ command "add" SectionCommon "add files to annex"
+ paramPaths (seek <$$> optParser)
-addOptions :: [Option]
-addOptions = includeDotFilesOption : fileMatchingOptions
+data AddOptions = AddOptions
+ { addThese :: CmdParams
+ , includeDotFiles :: Bool
+ }
-includeDotFilesOption :: Option
-includeDotFilesOption = flagOption [] "include-dotfiles" "don't skip dotfiles"
+optParser :: CmdParamsDesc -> Parser AddOptions
+optParser desc = AddOptions
+ <$> cmdParams desc
+ <*> switch
+ ( long "include-dotfiles"
+ <> help "don't skip dotfiles"
+ )
{- Add acts on both files not checked into git yet, and unlocked files.
-
- In direct mode, it acts on any files that have changed. -}
-seek :: CommandSeek
-seek ps = do
+seek :: AddOptions -> CommandSeek
+seek o = do
matcher <- largeFilesMatcher
- let go a = flip a ps $ \file -> ifM (checkFileMatcher matcher file <||> Annex.getState Annex.force)
+ let go a = flip a (addThese o) $ \file -> ifM (checkFileMatcher matcher file <||> Annex.getState Annex.force)
( start file
, startSmall file
)
- skipdotfiles <- not <$> Annex.getFlag (optionName includeDotFilesOption)
- go $ withFilesNotInGit skipdotfiles
+ go $ withFilesNotInGit (not $ includeDotFiles o)
ifM isDirect
( go withFilesMaybeModified
, go withFilesUnlocked
@@ -70,8 +77,8 @@ startSmall file = do
performAdd :: FilePath -> CommandPerform
performAdd file = do
- params <- forceParams
- Annex.Queue.addCommand "add" (params++[Param "--"]) [file]
+ ps <- forceParams
+ Annex.Queue.addCommand "add" (ps++[Param "--"]) [file]
next $ return True
{- The add subcommand annexes a file, generating a key for it using a
@@ -278,8 +285,8 @@ addLink :: FilePath -> Key -> Maybe InodeCache -> Annex ()
addLink file key mcache = ifM (coreSymlinks <$> Annex.getGitConfig)
( do
_ <- link file key mcache
- params <- forceParams
- Annex.Queue.addCommand "add" (params++[Param "--"]) [file]
+ ps <- forceParams
+ Annex.Queue.addCommand "add" (ps++[Param "--"]) [file]
, do
l <- link file key mcache
addAnnexLink l file