aboutsummaryrefslogtreecommitdiff
path: root/Command/CalcKey.hs
blob: 57e6f40c961079a8384a0c1800a0a286bdd10269 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{- git-annex command
 -
 - Copyright 2016 Joey Hess <id@joeyh.name>
 -
 - Licensed under the GNU GPL version 3 or higher.
 -}

module Command.CalcKey where

import Command
import Backend (genKey)
import Types.KeySource

cmd :: Command
cmd = noCommit $ noMessages $ dontCheck repoExists $
	command "calckey" SectionPlumbing 
		"calculates the key that would be used to refer to a file"
		(paramRepeating paramFile)
		(batchable run (pure ()))

run :: () -> String -> Annex Bool
run _ file = genKey (KeySource file file Nothing) Nothing >>= \case
	Just (k, _) -> do
		liftIO $ putStrLn $ key2file k
		return True
	Nothing -> return False