find --batch
This commit is contained in:
parent
1bd4809bd2
commit
6d79f9e755
4 changed files with 37 additions and 17 deletions
|
@ -17,6 +17,7 @@ import Limit
|
||||||
import qualified Utility.Format
|
import qualified Utility.Format
|
||||||
import Utility.DataUnits
|
import Utility.DataUnits
|
||||||
import Types.Key
|
import Types.Key
|
||||||
|
import CmdLine.Batch
|
||||||
|
|
||||||
cmd :: Command
|
cmd :: Command
|
||||||
cmd = withGlobalOptions annexedMatchingOptions $ mkCommand $
|
cmd = withGlobalOptions annexedMatchingOptions $ mkCommand $
|
||||||
|
@ -29,12 +30,14 @@ mkCommand = noCommit . noMessages . withGlobalOptions [jsonOption]
|
||||||
data FindOptions = FindOptions
|
data FindOptions = FindOptions
|
||||||
{ findThese :: CmdParams
|
{ findThese :: CmdParams
|
||||||
, formatOption :: Maybe Utility.Format.Format
|
, formatOption :: Maybe Utility.Format.Format
|
||||||
|
, batchOption :: BatchMode
|
||||||
}
|
}
|
||||||
|
|
||||||
optParser :: CmdParamsDesc -> Parser FindOptions
|
optParser :: CmdParamsDesc -> Parser FindOptions
|
||||||
optParser desc = FindOptions
|
optParser desc = FindOptions
|
||||||
<$> cmdParams desc
|
<$> cmdParams desc
|
||||||
<*> optional parseFormatOption
|
<*> optional parseFormatOption
|
||||||
|
<*> parseBatchOption
|
||||||
|
|
||||||
parseFormatOption :: Parser Utility.Format.Format
|
parseFormatOption :: Parser Utility.Format.Format
|
||||||
parseFormatOption =
|
parseFormatOption =
|
||||||
|
@ -48,15 +51,21 @@ parseFormatOption =
|
||||||
)
|
)
|
||||||
|
|
||||||
seek :: FindOptions -> CommandSeek
|
seek :: FindOptions -> CommandSeek
|
||||||
seek o = withFilesInGit (whenAnnexed $ start o) (findThese o)
|
seek o = case batchOption o of
|
||||||
|
NoBatch -> withFilesInGit go (findThese o)
|
||||||
|
Batch -> batchFiles go
|
||||||
|
where
|
||||||
|
go = whenAnnexed $ start o
|
||||||
|
|
||||||
|
-- only files inAnnex are shown, unless the user has requested
|
||||||
|
-- others via a limit
|
||||||
start :: FindOptions -> FilePath -> Key -> CommandStart
|
start :: FindOptions -> FilePath -> Key -> CommandStart
|
||||||
start o file key = do
|
start o file key = ifM (limited <||> inAnnex key)
|
||||||
-- only files inAnnex are shown, unless the user has requested
|
( do
|
||||||
-- others via a limit
|
|
||||||
whenM (limited <||> inAnnex key) $
|
|
||||||
showFormatted (formatOption o) file $ ("file", file) : keyVars key
|
showFormatted (formatOption o) file $ ("file", file) : keyVars key
|
||||||
stop
|
next $ next $ return True
|
||||||
|
, stop
|
||||||
|
)
|
||||||
|
|
||||||
showFormatted :: Maybe Utility.Format.Format -> String -> [(String, String)] -> Annex ()
|
showFormatted :: Maybe Utility.Format.Format -> String -> [(String, String)] -> Annex ()
|
||||||
showFormatted format unformatted vars =
|
showFormatted format unformatted vars =
|
||||||
|
|
2
debian/changelog
vendored
2
debian/changelog
vendored
|
@ -2,7 +2,7 @@ git-annex (6.20160115) UNRELEASED; urgency=medium
|
||||||
|
|
||||||
* whereis --json: Urls are now listed inside the remote that claims them,
|
* whereis --json: Urls are now listed inside the remote that claims them,
|
||||||
rather than all together at the end.
|
rather than all together at the end.
|
||||||
* info, add, whereis: Support --batch mode.
|
* info, add, whereis, find: Support --batch mode.
|
||||||
* Force output to be line-buffered, even when it's not connected to the
|
* Force output to be line-buffered, even when it's not connected to the
|
||||||
terminal. This is particuarly important for commands with --batch
|
terminal. This is particuarly important for commands with --batch
|
||||||
output, which was not always being flushed at an appropriate time.
|
output, which was not always being flushed at an appropriate time.
|
||||||
|
|
|
@ -13,6 +13,19 @@ finds files in the current directory and its subdirectories.
|
||||||
|
|
||||||
# OPTIONS
|
# OPTIONS
|
||||||
|
|
||||||
|
* matching options
|
||||||
|
|
||||||
|
The [[git-annex-matching-options]](1)
|
||||||
|
can be used to specify files to list.
|
||||||
|
|
||||||
|
By default, the find command only lists annexed files whose content is
|
||||||
|
currently present. Specifying any of the matching options will override
|
||||||
|
this default behavior.
|
||||||
|
|
||||||
|
To list all annexed files, present or not, specify `--include "*"`.
|
||||||
|
|
||||||
|
To list annexed files whose content is not present, specify `--not --in=here`
|
||||||
|
|
||||||
* `--print0`
|
* `--print0`
|
||||||
|
|
||||||
Output filenames terminated with nulls, for use with `xargs -0`
|
Output filenames terminated with nulls, for use with `xargs -0`
|
||||||
|
@ -41,18 +54,14 @@ finds files in the current directory and its subdirectories.
|
||||||
This is intended to be parsed by programs that use
|
This is intended to be parsed by programs that use
|
||||||
git-annex. Each line of output is a JSON object.
|
git-annex. Each line of output is a JSON object.
|
||||||
|
|
||||||
* matching options
|
* `--batch`
|
||||||
|
|
||||||
The [[git-annex-matching-options]](1)
|
|
||||||
can be used to specify files to list.
|
|
||||||
|
|
||||||
By default, the find command only lists annexed files whose content is
|
Enables batch mode, in which a file is read in a line from stdin,
|
||||||
currently present. Specifying any of the matching options will override
|
its information displayed, and repeat.
|
||||||
this default behavior.
|
|
||||||
|
|
||||||
To list all annexed files, present or not, specify `--include "*"`.
|
Note that if the file is not an annexed file, or is not present,
|
||||||
|
or otherwise doesn't meet the matching options, an empty line
|
||||||
To list annexed files whose content is not present, specify `--not --in=here`
|
will be output instead.
|
||||||
|
|
||||||
# SEE ALSO
|
# SEE ALSO
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
I am using `annex find filename` after running 'annex add` to figure out if file was added to annex or to git.
|
I am using `annex find filename` after running 'annex add` to figure out if file was added to annex or to git.
|
||||||
|
|
||||||
[[!meta author=yoh]]
|
[[!meta author=yoh]]
|
||||||
|
|
||||||
|
> [[done]] --[[Joey]]
|
||||||
|
|
Loading…
Reference in a new issue