summaryrefslogtreecommitdiff
path: root/Command
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-01-06 10:14:37 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-01-06 10:57:57 -0400
commit1f8a1058c96bd4ee11fcb353f0ede1842d79ab6a (patch)
tree0754233445da5c75737aa2b7866881d30939ec56 /Command
parentdf21cbfdd2b7342c206ebd4aea32d989328374dc (diff)
tweak
Diffstat (limited to 'Command')
-rw-r--r--Command/Copy.hs4
-rw-r--r--Command/Drop.hs5
-rw-r--r--Command/DropUnused.hs4
-rw-r--r--Command/Find.hs13
-rw-r--r--Command/Get.hs4
-rw-r--r--Command/Move.hs9
-rw-r--r--Command/Unused.hs5
7 files changed, 26 insertions, 18 deletions
diff --git a/Command/Copy.hs b/Command/Copy.hs
index c83c72412..32b83a526 100644
--- a/Command/Copy.hs
+++ b/Command/Copy.hs
@@ -17,8 +17,8 @@ def = [withOptions Command.Move.options $ command "copy" paramPaths seek
"copy content of files to/from another repository"]
seek :: [CommandSeek]
-seek = [withField "to" Remote.byName $ \to ->
- withField "from" Remote.byName $ \from ->
+seek = [withField Command.Move.toOption Remote.byName $ \to ->
+ withField Command.Move.fromOption Remote.byName $ \from ->
withNumCopies $ \n -> whenAnnexed $ start to from n]
-- A copy is just a move that does not delete the source file.
diff --git a/Command/Drop.hs b/Command/Drop.hs
index 07ea50df1..578ab62b9 100644
--- a/Command/Drop.hs
+++ b/Command/Drop.hs
@@ -16,16 +16,17 @@ import Logs.Location
import Logs.Trust
import Annex.Content
import Config
+import qualified Option
def :: [Command]
def = [withOptions [fromOption] $ command "drop" paramPaths seek
"indicate content of files not currently wanted"]
fromOption :: Option
-fromOption = fieldOption ['f'] "from" paramRemote "drop content from a remote"
+fromOption = Option.field ['f'] "from" paramRemote "drop content from a remote"
seek :: [CommandSeek]
-seek = [withField "from" Remote.byName $ \from -> withNumCopies $ \n ->
+seek = [withField fromOption Remote.byName $ \from -> withNumCopies $ \n ->
whenAnnexed $ start from n]
start :: Maybe Remote -> Maybe Int -> FilePath -> (Key, Backend) -> CommandStart
diff --git a/Command/DropUnused.hs b/Command/DropUnused.hs
index 1c5bf8b8c..0b2a60216 100644
--- a/Command/DropUnused.hs
+++ b/Command/DropUnused.hs
@@ -15,6 +15,7 @@ import qualified Annex
import qualified Command.Drop
import qualified Remote
import qualified Git
+import qualified Option
import Types.Key
type UnusedMap = M.Map String Key
@@ -51,13 +52,14 @@ start (unused, unusedbad, unusedtmp) s = search
next $ a key
perform :: Key -> CommandPerform
-perform key = maybe droplocal dropremote =<< Remote.byName =<< Annex.getField "from"
+perform key = maybe droplocal dropremote =<< Remote.byName =<< from
where
dropremote r = do
showAction $ "from " ++ Remote.name r
ok <- Remote.removeKey r key
next $ Command.Drop.cleanupRemote key r ok
droplocal = Command.Drop.performLocal key (Just 0) -- force drop
+ from = Annex.getField $ Option.name Command.Drop.fromOption
performOther :: (Key -> Git.Repo -> FilePath) -> Key -> CommandPerform
performOther filespec key = do
diff --git a/Command/Find.hs b/Command/Find.hs
index 8760cc947..902f50d2e 100644
--- a/Command/Find.hs
+++ b/Command/Find.hs
@@ -17,20 +17,23 @@ import qualified Annex
import qualified Utility.Format
import Utility.DataUnits
import Types.Key
+import qualified Option
def :: [Command]
def = [withOptions [formatOption, print0Option] $
command "find" paramPaths seek "lists available files"]
+formatOption :: Option
+formatOption = Option.field [] "format" paramFormat "control format of output"
+
print0Option :: Option
-print0Option = Option [] ["print0"] (NoArg $ Annex.setField "format" "${file}\0")
+print0Option = Option.Option [] ["print0"] (Option.NoArg set)
"terminate output with null"
-
-formatOption :: Option
-formatOption = fieldOption [] "format" paramFormat "control format of output"
+ where
+ set = Annex.setField (Option.name formatOption) "${file}\0"
seek :: [CommandSeek]
-seek = [withField "format" formatconverter $ \f ->
+seek = [withField formatOption formatconverter $ \f ->
withFilesInGit $ whenAnnexed $ start f]
where
formatconverter = return . maybe Nothing (Just . Utility.Format.gen)
diff --git a/Command/Get.hs b/Command/Get.hs
index 1a0435c36..5d032e13c 100644
--- a/Command/Get.hs
+++ b/Command/Get.hs
@@ -18,8 +18,8 @@ def = [withOptions [Command.Move.fromOption] $ command "get" paramPaths seek
"make content of annexed files available"]
seek :: [CommandSeek]
-seek = [withField "from" Remote.byName $ \from -> withNumCopies $ \n ->
- whenAnnexed $ start from n]
+seek = [withField Command.Move.fromOption Remote.byName $ \from ->
+ withNumCopies $ \n -> whenAnnexed $ start from n]
start :: Maybe Remote -> Maybe Int -> FilePath -> (Key, Backend) -> CommandStart
start from numcopies file (key, _) = stopUnless (not <$> inAnnex key) $
diff --git a/Command/Move.hs b/Command/Move.hs
index 4978283bf..2efaebbcb 100644
--- a/Command/Move.hs
+++ b/Command/Move.hs
@@ -14,23 +14,24 @@ import qualified Annex
import Annex.Content
import qualified Remote
import Annex.UUID
+import qualified Option
def :: [Command]
def = [withOptions options $ command "move" paramPaths seek
"move content of files to/from another repository"]
fromOption :: Option
-fromOption = fieldOption ['f'] "from" paramRemote "source remote"
+fromOption = Option.field ['f'] "from" paramRemote "source remote"
toOption :: Option
-toOption = fieldOption ['t'] "to" paramRemote "destination remote"
+toOption = Option.field ['t'] "to" paramRemote "destination remote"
options :: [Option]
options = [fromOption, toOption]
seek :: [CommandSeek]
-seek = [withField "to" Remote.byName $ \to ->
- withField "from" Remote.byName $ \from ->
+seek = [withField toOption Remote.byName $ \to ->
+ withField fromOption Remote.byName $ \from ->
withFilesInGit $ whenAnnexed $ start to from True]
start :: Maybe Remote -> Maybe Remote -> Bool -> FilePath -> (Key, Backend) -> CommandStart
diff --git a/Command/Unused.hs b/Command/Unused.hs
index a6883dce1..ffd4bef45 100644
--- a/Command/Unused.hs
+++ b/Command/Unused.hs
@@ -27,6 +27,7 @@ import qualified Git.LsTree as LsTree
import qualified Backend
import qualified Remote
import qualified Annex.Branch
+import qualified Option
import Annex.CatFile
def :: [Command]
@@ -34,7 +35,7 @@ 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"
+fromOption = Option.field ['f'] "from" paramRemote "remote to check for unused content"
seek :: [CommandSeek]
seek = [withNothing $ start]
@@ -42,7 +43,7 @@ seek = [withNothing $ start]
{- Finds unused content in the annex. -}
start :: CommandStart
start = do
- from <- Annex.getField "from"
+ from <- Annex.getField $ Option.name fromOption
let (name, action) = case from of
Nothing -> (".", checkUnused)
Just "." -> (".", checkUnused)