2016-04-20 17:49:42 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2016 Joey Hess <id@joeyh.name>
|
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2016-04-20 17:49:42 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.CalcKey where
|
|
|
|
|
|
|
|
import Command
|
2023-03-27 19:10:46 +00:00
|
|
|
import Backend (genKey, defaultBackend)
|
2016-04-20 17:49:42 +00:00
|
|
|
import Types.KeySource
|
2019-06-25 15:37:52 +00:00
|
|
|
import Utility.Metered
|
2023-04-12 18:03:44 +00:00
|
|
|
import Utility.Terminal
|
|
|
|
import Utility.SafeOutput
|
2016-04-20 17:49:42 +00:00
|
|
|
|
|
|
|
cmd :: Command
|
|
|
|
cmd = noCommit $ noMessages $ dontCheck repoExists $
|
2022-06-29 17:28:08 +00:00
|
|
|
withAnnexOptions [backendOption] $
|
|
|
|
command "calckey" SectionPlumbing
|
2023-03-14 02:39:16 +00:00
|
|
|
"calculate key for a file"
|
2022-06-29 17:28:08 +00:00
|
|
|
(paramRepeating paramFile)
|
|
|
|
(batchable run (pure ()))
|
2016-04-20 17:49:42 +00:00
|
|
|
|
2020-09-14 20:49:33 +00:00
|
|
|
run :: () -> SeekInput -> String -> Annex Bool
|
2023-03-27 19:10:46 +00:00
|
|
|
run _ _ file = tryNonAsync (genKey ks nullMeterUpdate =<< defaultBackend) >>= \case
|
2020-05-15 16:51:09 +00:00
|
|
|
Right (k, _) -> do
|
2023-04-12 18:03:44 +00:00
|
|
|
IsTerminal isterminal <- liftIO $ checkIsTerminal stdout
|
|
|
|
let sk = serializeKey k
|
|
|
|
liftIO $ putStrLn $ if isterminal then safeOutput sk else sk
|
2017-12-05 19:00:50 +00:00
|
|
|
return True
|
2020-05-15 16:51:09 +00:00
|
|
|
Left _err -> return False
|
2020-02-21 13:34:59 +00:00
|
|
|
where
|
|
|
|
ks = KeySource file' file' Nothing
|
|
|
|
file' = toRawFilePath file
|