aboutsummaryrefslogtreecommitdiff
path: root/Command/Find.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-07-10 12:47:35 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-07-10 12:47:35 -0400
commit9886c302ef538e538ec7d48b94374b9d2400004f (patch)
tree4c6b55c2ab31a977f1fbd89f131aac9ae3722119 /Command/Find.hs
parentbc9b0307cf427ab8ca6532c2ae4e0086e7ad4a4a (diff)
implement withGlobalOptions, and convert Find
Diffstat (limited to 'Command/Find.hs')
-rw-r--r--Command/Find.hs38
1 files changed, 22 insertions, 16 deletions
diff --git a/Command/Find.hs b/Command/Find.hs
index 5a0a08973..eb681d219 100644
--- a/Command/Find.hs
+++ b/Command/Find.hs
@@ -14,7 +14,6 @@ import Common.Annex
import Command
import Annex.Content
import Limit
-import qualified Annex
import qualified Utility.Format
import Utility.DataUnits
import Types.Key
@@ -22,27 +21,34 @@ import Types.Key
cmd :: Command
cmd = withOptions annexedMatchingOptions $ mkCommand $
command "find" SectionQuery "lists available files"
- paramPaths (withParams seek)
+ paramPaths (seek <$$> optParser)
mkCommand :: Command -> Command
-mkCommand = noCommit . noMessages . withOptions [formatOption, print0Option, jsonOption]
+mkCommand = noCommit . noMessages . withGlobalOptions [jsonOption]
-formatOption :: Option
-formatOption = fieldOption [] "format" paramFormat "control format of output"
+data FindOptions = FindOptions
+ { findThese :: CmdParams
+ , formatOption :: Maybe Utility.Format.Format
+ }
-getFormat :: Annex (Maybe Utility.Format.Format)
-getFormat = getOptionField formatOption $ return . fmap Utility.Format.gen
+optParser :: CmdParamsDesc -> Parser FindOptions
+optParser desc = FindOptions
+ <$> cmdParams desc
+ <*> optional parseFormatOption
-print0Option :: Option
-print0Option = Option [] ["print0"] (NoArg set)
- "terminate output with null"
- where
- set = Annex.setField (optionName formatOption) "${file}\0"
+parseFormatOption :: Parser Utility.Format.Format
+parseFormatOption =
+ option (Utility.Format.gen <$> str)
+ ( long "format" <> metavar paramFormat
+ <> help "control format of output"
+ )
+ <|> flag' (Utility.Format.gen "${file}\0")
+ ( long "print0"
+ <> help "output filenames terminated with nulls"
+ )
-seek :: CmdParams -> CommandSeek
-seek ps = do
- format <- getFormat
- withFilesInGit (whenAnnexed $ start format) ps
+seek :: FindOptions -> CommandSeek
+seek o = withFilesInGit (whenAnnexed $ start (formatOption o)) (findThese o)
start :: Maybe Utility.Format.Format -> FilePath -> Key -> CommandStart
start format file key = do