2010-11-14 16:35:05 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2012-01-06 02:48:59 +00:00
|
|
|
- Copyright 2010-2012 Joey Hess <joey@kitenet.net>
|
2010-11-14 16:35:05 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Find where
|
|
|
|
|
2011-12-22 22:31:44 +00:00
|
|
|
import qualified Data.Map as M
|
|
|
|
|
2011-10-05 20:02:51 +00:00
|
|
|
import Common.Annex
|
2010-11-14 16:35:05 +00:00
|
|
|
import Command
|
2011-10-04 04:40:47 +00:00
|
|
|
import Annex.Content
|
2011-09-19 00:41:51 +00:00
|
|
|
import Limit
|
2011-11-22 18:06:31 +00:00
|
|
|
import qualified Annex
|
2011-12-22 22:31:44 +00:00
|
|
|
import qualified Utility.Format
|
|
|
|
import Utility.DataUnits
|
|
|
|
import Types.Key
|
2012-01-06 14:14:37 +00:00
|
|
|
import qualified Option
|
2010-11-14 16:35:05 +00:00
|
|
|
|
2011-10-29 19:19:05 +00:00
|
|
|
def :: [Command]
|
2012-01-06 02:48:59 +00:00
|
|
|
def = [withOptions [formatOption, print0Option] $
|
|
|
|
command "find" paramPaths seek "lists available files"]
|
|
|
|
|
2012-01-06 14:14:37 +00:00
|
|
|
formatOption :: Option
|
|
|
|
formatOption = Option.field [] "format" paramFormat "control format of output"
|
|
|
|
|
2012-01-06 02:48:59 +00:00
|
|
|
print0Option :: Option
|
2012-01-06 14:14:37 +00:00
|
|
|
print0Option = Option.Option [] ["print0"] (Option.NoArg set)
|
2012-01-06 02:48:59 +00:00
|
|
|
"terminate output with null"
|
2012-01-06 14:14:37 +00:00
|
|
|
where
|
|
|
|
set = Annex.setField (Option.name formatOption) "${file}\0"
|
more command-specific options
Made --from and --to command-specific options.
Added generic storage for values of command-specific options,
which allows removing some of the special case fields in AnnexState.
(Also added generic storage for command-specific flags, although there are
not yet any.)
Note that this storage uses a Map, so repeatedly looking up the same value
is slightly more expensive than looking up an AnnexState field. But, the
value can be looked up once in the seek stage, transformed as necessary,
and passed in a closure to the start stage, and this avoids that overhead.
Still, I'm hesitant to use this for things like force or fast flags.
It's probably best to reserve it for flags that are only used by a few
commands, or options like --from and --to that it's important only be
allowed to be used with commands that implement them, to avoid user
confusion.
2012-01-06 07:06:25 +00:00
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
seek :: [CommandSeek]
|
2012-01-06 14:14:37 +00:00
|
|
|
seek = [withField formatOption formatconverter $ \f ->
|
more command-specific options
Made --from and --to command-specific options.
Added generic storage for values of command-specific options,
which allows removing some of the special case fields in AnnexState.
(Also added generic storage for command-specific flags, although there are
not yet any.)
Note that this storage uses a Map, so repeatedly looking up the same value
is slightly more expensive than looking up an AnnexState field. But, the
value can be looked up once in the seek stage, transformed as necessary,
and passed in a closure to the start stage, and this avoids that overhead.
Still, I'm hesitant to use this for things like force or fast flags.
It's probably best to reserve it for flags that are only used by a few
commands, or options like --from and --to that it's important only be
allowed to be used with commands that implement them, to avoid user
confusion.
2012-01-06 07:06:25 +00:00
|
|
|
withFilesInGit $ whenAnnexed $ start f]
|
|
|
|
where
|
2012-01-06 08:02:35 +00:00
|
|
|
formatconverter = return . maybe Nothing (Just . Utility.Format.gen)
|
2010-11-14 16:35:05 +00:00
|
|
|
|
more command-specific options
Made --from and --to command-specific options.
Added generic storage for values of command-specific options,
which allows removing some of the special case fields in AnnexState.
(Also added generic storage for command-specific flags, although there are
not yet any.)
Note that this storage uses a Map, so repeatedly looking up the same value
is slightly more expensive than looking up an AnnexState field. But, the
value can be looked up once in the seek stage, transformed as necessary,
and passed in a closure to the start stage, and this avoids that overhead.
Still, I'm hesitant to use this for things like force or fast flags.
It's probably best to reserve it for flags that are only used by a few
commands, or options like --from and --to that it's important only be
allowed to be used with commands that implement them, to avoid user
confusion.
2012-01-06 07:06:25 +00:00
|
|
|
start :: Maybe Utility.Format.Format -> FilePath -> (Key, Backend) -> CommandStart
|
|
|
|
start format file (key, _) = do
|
2011-09-19 00:41:51 +00:00
|
|
|
-- only files inAnnex are shown, unless the user has requested
|
|
|
|
-- others via a limit
|
2011-12-23 17:19:28 +00:00
|
|
|
whenM (liftM2 (||) limited (inAnnex key)) $
|
more command-specific options
Made --from and --to command-specific options.
Added generic storage for values of command-specific options,
which allows removing some of the special case fields in AnnexState.
(Also added generic storage for command-specific flags, although there are
not yet any.)
Note that this storage uses a Map, so repeatedly looking up the same value
is slightly more expensive than looking up an AnnexState field. But, the
value can be looked up once in the seek stage, transformed as necessary,
and passed in a closure to the start stage, and this avoids that overhead.
Still, I'm hesitant to use this for things like force or fast flags.
It's probably best to reserve it for flags that are only used by a few
commands, or options like --from and --to that it's important only be
allowed to be used with commands that implement them, to avoid user
confusion.
2012-01-06 07:06:25 +00:00
|
|
|
unlessM (showFullJSON vars) $
|
|
|
|
case format of
|
2011-12-23 02:03:18 +00:00
|
|
|
Nothing -> liftIO $ putStrLn file
|
|
|
|
Just formatter -> liftIO $ putStr $
|
|
|
|
Utility.Format.format formatter $
|
|
|
|
M.fromList vars
|
2011-05-15 06:02:46 +00:00
|
|
|
stop
|
2011-12-22 22:31:44 +00:00
|
|
|
where
|
2011-12-23 02:03:18 +00:00
|
|
|
vars =
|
2011-12-22 22:31:44 +00:00
|
|
|
[ ("file", file)
|
|
|
|
, ("key", show key)
|
|
|
|
, ("backend", keyBackendName key)
|
|
|
|
, ("bytesize", size show)
|
|
|
|
, ("humansize", size $ roughSize storageUnits True)
|
|
|
|
]
|
|
|
|
size c = maybe "unknown" c $ keySize key
|