2023-01-17 18:42:29 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2023 Joey Hess <id@joeyh.name>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.FindKeys where
|
|
|
|
|
|
|
|
import Command
|
|
|
|
import qualified Command.Find
|
2023-04-11 18:57:09 +00:00
|
|
|
import qualified Utility.Format
|
2023-04-12 17:48:21 +00:00
|
|
|
import Utility.Terminal
|
2023-01-17 18:42:29 +00:00
|
|
|
|
|
|
|
cmd :: Command
|
|
|
|
cmd = withAnnexOptions [keyMatchingOptions] $ Command.Find.mkCommand $
|
|
|
|
command "findkeys" SectionQuery "lists available keys"
|
|
|
|
paramNothing (seek <$$> optParser)
|
|
|
|
|
|
|
|
data FindKeysOptions = FindKeysOptions
|
|
|
|
{ formatOption :: Maybe Utility.Format.Format
|
|
|
|
}
|
|
|
|
|
|
|
|
optParser :: CmdParamsDesc -> Parser FindKeysOptions
|
|
|
|
optParser _ = FindKeysOptions
|
|
|
|
<$> optional (Command.Find.parseFormatOption' "${key}\0")
|
|
|
|
|
|
|
|
seek :: FindKeysOptions -> CommandSeek
|
|
|
|
seek o = do
|
2023-04-11 18:57:09 +00:00
|
|
|
isterminal <- liftIO $ checkIsTerminal stdout
|
2023-01-17 18:42:29 +00:00
|
|
|
seeker <- Command.Find.contentPresentUnlessLimited $ AnnexedFileSeeker
|
|
|
|
{ checkContentPresent = Nothing
|
|
|
|
, usesLocationLog = False
|
|
|
|
-- startAction is not actually used since this
|
|
|
|
-- is not used to seek files
|
2023-12-06 17:04:32 +00:00
|
|
|
, startAction = \_ _ _ key -> start' o isterminal key
|
2023-01-17 18:42:29 +00:00
|
|
|
}
|
|
|
|
withKeyOptions (Just WantAllKeys) False seeker
|
2023-04-11 18:57:09 +00:00
|
|
|
(commandAction . start o isterminal)
|
2023-01-17 18:42:29 +00:00
|
|
|
(const noop) (WorkTreeItems [])
|
|
|
|
|
2023-04-11 18:57:09 +00:00
|
|
|
start :: FindKeysOptions -> IsTerminal -> (SeekInput, Key, ActionItem) -> CommandStart
|
|
|
|
start o isterminal (_si, key, _ai) = start' o isterminal key
|
2023-01-17 18:42:29 +00:00
|
|
|
|
2023-04-11 18:57:09 +00:00
|
|
|
start' :: FindKeysOptions -> IsTerminal -> Key -> CommandStart
|
|
|
|
start' o isterminal key = startingCustomOutput key $ do
|
|
|
|
Command.Find.showFormatted isterminal (formatOption o) (serializeKey' key)
|
2023-01-17 18:42:29 +00:00
|
|
|
(Command.Find.formatVars key (AssociatedFile Nothing))
|
|
|
|
next $ return True
|