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